Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Apr 24, 2023
2 parents b039e4d + e6d7c96 commit 0b2fe3b
Show file tree
Hide file tree
Showing 20 changed files with 1,465 additions and 883 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ jobs:
ELASTICSEARCH_PROTOCOL: http
ELASTICSEARCH_HOST: 127.0.0.1
ELASTICSEARCH_PORT: 9200
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
matrix:
cfengine: [ "lucee@5", "adobe@2018", "adobe@2021" ]
ELASTICSEARCH_VERSION: [ "7.17.8", "8.5.3" ]
ELASTICSEARCH_VERSION: [ "7.17.8", "8.7.0" ]
experimental: [ false ]
include:
- cfengine: "adobe@2023"
ELASTICSEARCH_VERSION: "8.7.0"
experimental: true
steps:
- name: Checkout Repository
uses: actions/[email protected]
Expand Down
179 changes: 88 additions & 91 deletions ModuleConfig.cfc
Original file line number Diff line number Diff line change
@@ -1,105 +1,102 @@
/**
*********************************************************************************
* Your Copyright
********************************************************************************
*/
component{
*********************************************************************************
* Your Copyright
********************************************************************************
*/
component {

// Module Properties
this.title = "cbElasticSearch";
this.author = "Jon Clausen <[email protected]>";
this.webURL = "";
this.description = "Coldbox Module with Fluent API for ElasticSearch";
this.version = "@build.version@[email protected]@";
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = true;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = true;
// Module Entry Point
this.entryPoint = "cbElasticsearch";
// Model Namespace
this.modelNamespace = "cbElasticsearch";
// CF Mapping
this.cfmapping = "cbElasticsearch";
// Auto-map models
this.autoMapModels = true;
// Module Dependencies That Must Be Loaded First, use internal names or aliases
this.dependencies = [ "hyper" ];
// Auto-parse parent settings
this.parseParentSettings = true;
// Module Properties
this.title = "cbElasticSearch";
this.author = "Jon Clausen <[email protected]>";
this.webURL = "";
this.description = "Coldbox Module with Fluent API for ElasticSearch";
this.version = "@build.version@[email protected]@";
// If true, looks for views in the parent first, if not found, then in the module. Else vice-versa
this.viewParentLookup = true;
// If true, looks for layouts in the parent first, if not found, then in module. Else vice-versa
this.layoutParentLookup = true;
// Module Entry Point
this.entryPoint = "cbElasticsearch";
// Model Namespace
this.modelNamespace = "cbElasticsearch";
// CF Mapping
this.cfmapping = "cbElasticsearch";
// Auto-map models
this.autoMapModels = true;
// Module Dependencies That Must Be Loaded First, use internal names or aliases
this.dependencies = [ "hyper" ];
// Auto-parse parent settings
this.parseParentSettings = true;

variables.configStruct = {};
variables.configStruct = {};


function configure(){
function configure(){
// Default settings
settings = {
// The default hosts - an array of host connections
// - REST-based clients (e.g. JEST): round robin connections will be used
// - Socket-based clients (e.g. Transport): cluster-aware routing used
versionTarget : getSystemSetting( "ELASTICSEARCH_VERSION", "" ),
hosts : [
// The default connection is made to http://127.0.0.1:9200
{
serverProtocol : getSystemSetting( "ELASTICSEARCH_PROTOCOL", "http" ),
serverName : getSystemSetting( "ELASTICSEARCH_HOST", "127.0.0.1" ),
serverPort : getSystemSetting( "ELASTICSEARCH_PORT", 9200 )
}
],
// The default credentials for access, if any - may also be overridden when searching index collections
defaultCredentials : {
"username" : getSystemSetting( "ELASTICSEARCH_USERNAME", "" ),
"password" : getSystemSetting( "ELASTICSEARCH_PASSWORD", "" )
},
// The default index
defaultIndex : getSystemSetting( "ELASTICSEARCH_INDEX", "cbElasticsearch" ),
// The default number of shards to use when creating an index
defaultIndexShards : getSystemSetting( "ELASTICSEARCH_SHARDS", 5 ),
// The default number of index replicas to create
defaultIndexReplicas : getSystemSetting( "ELASTICSEARCH_REPLICAS", 0 ),
// Whether to use separate threads for client transactions
multiThreaded : true,
// The maximum amount of time to wait until releasing a connection (in seconds)
maxConnectionIdleTime : 30,
// The maximum number of connections allowed per route ( e.g. search URI endpoint )
maxConnectionsPerRoute : 10,
// The maxium number of connections, in total for all Elasticsearch requests
maxConnections : getSystemSetting( "ELASTICSEARCH_MAX_CONNECTIONS", 100 ),
// Read timeout - the read timeout in milliseconds
readTimeout : getSystemSetting( "ELASTICSEARCH_READ_TIMEOUT", 3000 ),
// Connection timeout - timeout attempts to connect to elasticsearch after this timeout
connectionTimeout : getSystemSetting( "ELASTICSEARCH_CONNECT_TIMEOUT", 3000 )
};

// Default settings
settings = {
// The default hosts - an array of host connections
// - REST-based clients (e.g. JEST): round robin connections will be used
// - Socket-based clients (e.g. Transport): cluster-aware routing used
versionTarget = getSystemSetting( "ELASTICSEARCH_VERSION", '' ),
hosts = [
//The default connection is made to http://127.0.0.1:9200
{
serverProtocol: getSystemSetting( "ELASTICSEARCH_PROTOCOL", "http" ),
serverName: getSystemSetting( "ELASTICSEARCH_HOST", "127.0.0.1" ),
serverPort: getSystemSetting( "ELASTICSEARCH_PORT", 9200 )
}
],
// The default credentials for access, if any - may also be overridden when searching index collections
defaultCredentials = {
"username" : getSystemSetting( "ELASTICSEARCH_USERNAME", "" ),
"password" : getSystemSetting( "ELASTICSEARCH_PASSWORD", "" )
},
// The default index
defaultIndex = getSystemSetting( "ELASTICSEARCH_INDEX", "cbElasticsearch" ),
// The default number of shards to use when creating an index
defaultIndexShards = getSystemSetting( "ELASTICSEARCH_SHARDS", 5 ),
// The default number of index replicas to create
defaultIndexReplicas = getSystemSetting( "ELASTICSEARCH_REPLICAS", 0 ),
// Whether to use separate threads for client transactions
multiThreaded = true,
// The maximum amount of time to wait until releasing a connection (in seconds)
maxConnectionIdleTime = 30,
// The maximum number of connections allowed per route ( e.g. search URI endpoint )
maxConnectionsPerRoute = 10,
// The maxium number of connections, in total for all Elasticsearch requests
maxConnections = getSystemSetting( "ELASTICSEARCH_MAX_CONNECTIONS", 100 ),
// Read timeout - the read timeout in milliseconds
readTimeout = getSystemSetting( "ELASTICSEARCH_READ_TIMEOUT", 3000 ),
// Connection timeout - timeout attempts to connect to elasticsearch after this timeout
connectionTimeout = getSystemSetting( "ELASTICSEARCH_CONNECT_TIMEOUT", 3000 )
};

// Custom Declared Points
interceptorSettings = {
customInterceptionPoints = [
// Custom Declared Points
interceptorSettings = {
customInterceptionPoints : [
"cbElasticsearchPreSave",
"cbElasticsearchPostSave"
]
};

// Custom Declared Interceptors
interceptors = [];

}
};

/**
* Fired when the module is registered and activated.
*/
function onLoad(){
/**
* Main Configuration Object Singleton
**/
binder.map( "Config@cbElasticsearch" )
.to( '#this.cfmapping#.models.Config' )
.threadSafe()
.asSingleton();
// Custom Declared Interceptors
interceptors = [];
}

binder.map( "Client@cbElasticsearch" )
.to( '#this.cfmapping#.models.io.HyperClient' );
/**
* Fired when the module is registered and activated.
*/
function onLoad(){
/**
* Main Configuration Object Singleton
**/
binder
.map( "Config@cbElasticsearch" )
.to( "#this.cfmapping#.models.Config" )
.threadSafe()
.asSingleton();

}
binder.map( "Client@cbElasticsearch" ).to( "#this.cfmapping#.models.io.HyperClient" );
}

}
2 changes: 1 addition & 1 deletion box.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name":"Elasticsearch for the Coldbox Framework",
"author":"Ortus Solutions <[email protected]",
"location":"https://downloads.ortussolutions.com/ortussolutions/coldbox-modules/cbelasticsearch/@build.version@/[email protected]@[email protected]@.zip",
"version":"3.0.3",
"version":"3.1.0",
"slug":"cbelasticsearch",
"type":"modules",
"homepage":"https://cbelasticsearch.ortusbooks.com",
Expand Down
12 changes: 12 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

----
# [3.1.0] - 04-24-2023
### Added
* Added support for [scripted and runtime fields](https://cbelasticsearch.ortusbooks.com/indices/managing-indices)
* [Added `getTermsEnum` to client](https://cbelasticsearch.ortusbooks.com/searching/search#terms-enum) to allow for fetching autocompletion terms and picklists
* Added [generic `set` method to SearchBuilder](https://cbelasticsearch.ortusbooks.com/searching/search) to allow for ad-hoc body parameters

### Fixed
* Fixed an issue with `filterRange` method to allow compatibility when used with `filterTerms` and `filterTerm`

### Changed
* Renamed `startRows`/`maxRows` properties in search builder to `from`/`size` to better match ES query syntax. Adds custom `setStartRows` and `setMaxRows` methods which pass through.

# [3.0.3] - 04-18-2023
### Fixed
* Fixed regex used to detect Lucee HTML formatted error messages
Expand Down
30 changes: 30 additions & 0 deletions docs/Indices/Managing-Indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ var mappings = getInstance( "Client@CBElasticsearch" ).refreshIndex(
[ "reviews", "book*" ],
{ "ignore_unavailable" : true }
);
```

## Getting Index Statistics

Expand Down Expand Up @@ -212,6 +213,35 @@ var mappings = getInstance( "Client@CBElasticsearch" )
);
```

## Creating Runtime Fields

Elasticsearch allows [mapping runtime fields](https://www.elastic.co/guide/en/elasticsearch/reference/current/runtime-mapping-fields.html), which are fields calculated at search time and returned in the `"fields"` array.

```js
var script = getInstance( "Util@CBElasticsearch" )
.formatToPainless("
if( doc['summary'].value.contains('love') ){ emit('😍');}
if( doc['summary'].value.contains('great') ){ emit('🚀');}
if( doc['summary'].value.contains('hate') ){ emit('😡');}
if( doc['summary'].value.contains('broke') ){ emit('💔');}
");
getInstance( "Client@CBElasticsearch" )
.patch( "reviews", {
"mappings" : {
"runtime" : {
"summarized_emotions" : {
"type" : "text",
"script" : {
"source" : script
}
}
}
}
} );
```

This `summarized_emotions` field [can then be retrieved during a search](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-fields.html) to display an array of emotions matching the review summary.

## Deleting an Index

All good things must come to an end, eh? You can use `Client.deleteIndex()` to delete an existing index:
Expand Down
Loading

0 comments on commit 0b2fe3b

Please sign in to comment.