Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 `.withHeader( "X-Custom-Header", "MyValue" )` to fluently set headers on builders
7 changes: 6 additions & 1 deletion models/AliasBuilder.cfc
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
component accessors="true" {
component accessors="true" extends="BaseModel" {

property name="action";
property name="indexName";
property name="aliasName";

function init(){
super.init();
return this;
}

function add( required string indexName, required string aliasName ){
arguments.action = "add";
return new ( argumentCollection = arguments );
Expand Down
57 changes: 57 additions & 0 deletions models/BaseModel.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
*
* Base Model for Fluent Request Overrides
*
* Provides a foundation for builder and model objects to support per-request
* configuration overrides via fluent method chaining. All builder classes
* (IndexBuilder, SearchBuilder, AliasBuilder, Document, Pipeline, etc.) extend
* this component to inherit request override capabilities.
*
* @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 missingMethodName, struct missingMethodArguments ){
if ( left( missingMethodName, 4 ) == "with" ) {
var args = [];
if ( !isNull( missingMethodArguments ) ) {
args = missingMethodArguments.reduce( function( acc, key, val ){
acc.append( val );
return acc;
}, [] );
}
variables.requestOverrides[ lCase( replace( missingMethodName, "with", "" ) ) ] = args;
return this;
}
// For all other missing methods, raise a proper missing-method exception
throw(
type = "MissingMethodException",
message = "No such method found for #missingMethodName# on #getMetadata( this ).name#.",
detail = "Use with#missingMethodName# to set default values for request overrides on this model."
);
}

}
7 changes: 6 additions & 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 Expand Up @@ -51,6 +51,11 @@ component accessors="true" {
*/
property name="fields" type="struct";

function init(){
super.init();
return this;
}

function onDIComplete(){
reset();
}
Expand Down
7 changes: 6 additions & 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 All @@ -20,6 +20,11 @@ component accessors="true" {
* @phases a struct of phases ( optional )
* @meta optional struct of meta
*/
ILMPolicyBuilder function init(){
super.init();
return this;
}

ILMPolicyBuilder function new(
required string policyName,
struct phases,
Expand Down
7 changes: 6 additions & 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 All @@ -25,6 +25,11 @@ component accessors="true" {
property name="aliases";


function init(){
super.init();
return this;
}

function onDIComplete(){
reset();
}
Expand Down
3 changes: 2 additions & 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 Expand Up @@ -30,6 +30,7 @@ component accessors="true" threadSafe {


cbElasticsearch.models.Pipeline function init( struct definition ){
super.init();
variables.description = "";
variables.processors = [];

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

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

/**
* Property containing the index name of the active builder search
**/
property name="index";

/**
* Property containing the object type within the index
**/
Expand Down Expand Up @@ -104,6 +105,11 @@ component accessors="true" {
property name="size";
property name="from";

function init(){
super.init();
return this;
}


function onDIComplete(){
reset();
Expand Down
Loading
Loading