Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Sep 26, 2024
2 parents a030351 + 150ec57 commit cedc876
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
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.4.0",
"version":"3.4.1",
"slug":"cbelasticsearch",
"type":"modules",
"homepage":"https://cbelasticsearch.ortusbooks.com",
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

* Add optional `field` argument to `getMappings` client method, which allows for wildcard search and filtering of mappings ( e.g. `(GET) /logs-coldobx-*/_mapping/*application` )

## [3.4.0] - 2024-09-26

### Added
Expand Down
25 changes: 22 additions & 3 deletions models/io/HyperClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -266,18 +266,37 @@ component accessors="true" threadSafe singleton {
}
}



/**
* Returns the mappings for an index
*
* @indexName string the name of the index
* @field an optional field name or field pattern
*/
struct function getMappings( required string indexName ){
var response = variables.nodePool.newRequest( arguments.indexName & "/_mapping", "GET" ).send();
struct function getMappings( required string indexName, string field ){
var path = arguments.indexName & "/_mapping";
if( !isNull( arguments.field ) ){
path &= "/field/" & arguments.field;
}
var response = variables.nodePool.newRequest( path, "GET" ).send();

if ( response.getStatusCode() != 200 ) {
onResponseFailure( response );
} else {
return response.json()[ indexName ].mappings;
return isNull( arguments.field )
? response.json()[ indexName ].mappings
: response.json().reduce( ( acc, indexKey, value ) => {
value.mappings.keyArray().each( ( mappingKey ) => {
if( !acc.keyExists( mappingKey ) ){
acc[ mappingKey ] = value.mappings[ mappingKey ];
acc[ mappingKey ]["indices"] = [ indexKey ];
} else {
acc[ mappingKey ]["indices"].append( indexKey );
}
} );
return acc;
}, {} );
}
}

Expand Down
9 changes: 6 additions & 3 deletions test-harness/tests/specs/unit/ClientTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ component extends="HyperClientTest" {
function beforeAll(){
super.beforeAll();

variables.model = getWirebox().getInstance( "HyperClient@cbelasticsearch" );
variables.model = getWirebox().getInstance( "Client@cbelasticsearch" );

super.beforeAll();
}

function run(){
// all of our native client methods are interface and pass through to the native client. Those tests after the core tests are completed
super.run();
describe( "Ensures the mapping for the client is present", function(){
it( "Checks the instance", function(){
expect( variables.model ).toBeInstanceOf( "cbelasticsearch.models.io.HyperClient" );
});
} );
}

}
13 changes: 13 additions & 0 deletions test-harness/tests/specs/unit/HyperClientTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ component extends="coldbox.system.testing.BaseTestCase" {

expect( mappings.properties ).toHaveKey( "modifiedTime" );
expect( mappings.properties.modifiedTime ).toHaveKey( "format" );

var fieldMappings = variables.model.getMappings( variables.testIndexName, "*modifiedTime*" );

debug( fieldMappings );

expect( fieldMappings )
.toBeStruct()
.toHaveKey( "modifiedTime" );

expect( fieldMappings.modifiedTime ).toBeStruct()
.toHaveKey( "full_name" )
.toHaveKey( "mapping" )
.toHaveKey( "indices" );

} );

Expand Down

0 comments on commit cedc876

Please sign in to comment.