Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 76 additions & 1 deletion docs/Getting-Started/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,79 @@ You will need to read these settings into the coldfusion server upon server star

{% hint style="warning" %}
For security reasons, make sure to add `.env` to your `.gitignore` file to avoid committing environment secrets to github/your git server.
{% endhint %}
{% endhint %}

## Request Parameter Overrides

In addition to global configuration settings, you can override request-specific parameters on a per-call basis. This is useful when you need different timeouts or settings for specific operations.

### Builder-Level Overrides

Builder objects (like `IndexBuilder`, `SearchBuilder`, `Document`, etc.) extend `BaseModel` and support fluent configuration of request parameters using the `.with*()` method:

```cfc
// Create an index with a custom 10-second timeout
get( "IndexBuilder@cbelasticsearch" )
.new( name = "books" )
.withTimeout( 10 )
.save();
```

Here's an example of setting a custom header on a search builder:

```cfc
// Search with custom headers
get( "SearchBuilder@cbelasticsearch" )
.new()
.withHeader( "X-Custom-Header", "MyValue" )
.setQuery( ... )
.execute();
```

### Direct Client Method Overrides

All public methods in `HyperClient` accept a `requestOverrides` struct as the final parameter. This allows you to pass request-specific configuration directly to the client:

```cfc
// Check if index exists with a 45-second timeout
get( "HyperClient@cbelasticsearch" )
.indexExists( "foo", { "timeout" : 45 } );

// Get index settings with custom timeout
get( "HyperClient@cbelasticsearch" )
.getSettings( "myIndex", { "timeout" : 30 } );

// Search with request overrides
get( "HyperClient@cbelasticsearch" )
.executeSearch(
searchBuilder,
{ "timeout" : 60, "readTimeout" : 5000 }
);
```

### Merging Overrides

When both builder-level and client-level overrides are provided, they are merged together with client-level overrides taking precedence:

```cfc
var builder = get( "IndexBuilder@cbelasticsearch" )
.new( name = "books" )
.withTimeout( 10 ); // Builder-level: 10 seconds

// Client call with override - the 30-second timeout wins
get( "HyperClient@cbelasticsearch" )
.applyIndex( builder, { "timeout" : 30 } );
```

### Available Override Parameters

Any HyperRequest parameters can be overridden on a per-request basis. These include:

- `timeout` - Connection timeout in seconds
- `username` - Username for authentication
- `password` - Password for authentication
- `maximumRedirects` - Maximum number of redirects to follow
- `retries` - Number of times to retry a request in case of failure
- `proxyUser` - Username for proxy authentication
- `proxyPassword` - Password for proxy authentication
- `headers` - Struct of custom headers to include in the request - use `.withHeaders( { "X-Custom-Header" : "MyValue" } )` to fluently set headers on builders
Comment thread
michaelborn marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion models/AliasBuilder.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component accessors="true" {
component accessors="true" extends="BaseModel" {

property name="action";
property name="indexName";
Expand Down
47 changes: 47 additions & 0 deletions models/BaseModel.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
*
* Elasticsearch Document Object
*
* @package cbElasticsearch.models
* @author Jon Clausen <jclausen@ortussolutions.com>
* @license Apache v2.0 <http: // www.apache.org / licenses/>
*
*/
component accessors="true" {
Comment thread
michaelborn marked this conversation as resolved.

property name="requestOverrides" type="struct";

public BaseModel function init(){
variables.requestOverrides = {};
return this;
}

public BaseModel function withRequestOverrides( struct overrides ){
setRequestOverrides( arguments.overrides );
return this;
}

/**
* Handles any missing methods that start with "with" and adds the value to the requestOverrides struct for request configuration
* Example: withTimeout( 1000 ) would set a default timeout of 1000ms on all requests created by this model
*
* @param methodName the name of the method being called
* @param arguments the arguments passed to the method, where arguments[1] is expected to be the value to set for the default
* @return returns the model instance for chaining
*/
public BaseModel function onMissingMethod( string methodName, struct arguments ){
var args = [];
if ( !isNull( arguments[ 2 ] ) ) {
args = arguments[ 2 ].reduce( function( acc, key, val ){
acc.append( val );
return acc;
}, [] );
}
if ( left( methodName, 4 ) == "with" ) {
variables.requestOverrides[ lCase( mid( methodName, 5 ) ) ] = args;
return this;
}
return this;
Comment thread
michaelborn marked this conversation as resolved.
Outdated
}

}
2 changes: 1 addition & 1 deletion models/Document.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license Apache v2.0 <http: // www.apache.org / licenses/>
*
*/
component accessors="true" {
component accessors="true" extends="BaseModel" {

property name="config" inject="Config@cbelasticsearch";

Expand Down
2 changes: 1 addition & 1 deletion models/ILMPolicyBuilder.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component accessors="true" {
component accessors="true" extends="BaseModel" {

property name="policyName";

Expand Down
2 changes: 1 addition & 1 deletion models/IndexBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license Apache v2.0 <http: // www.apache.org / licenses/>
*
*/
component accessors="true" {
component accessors="true" extends="BaseModel" {

// The name of our index
property name="indexName";
Expand Down
2 changes: 1 addition & 1 deletion models/Pipeline.cfc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
component accessors="true" threadSafe {
component accessors="true" extends="BaseModel" threadSafe {
Comment thread
michaelborn marked this conversation as resolved.

property name="Util" inject="Util@cbelasticsearch";

Expand Down
2 changes: 1 addition & 1 deletion models/SearchBuilder.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license Apache v2.0 <http: // www.apache.org / licenses/>
*
*/
component accessors="true" {
component accessors="true" extends="BaseModel" {

property name="configObject" inject="Config@cbelasticsearch";

Expand Down
Loading
Loading