Skip to content

Commit

Permalink
Add mappings handling for wildcard pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
jclausen committed Dec 13, 2024
1 parent 6f8cac7 commit 83bf2c7
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions models/io/HyperClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ component accessors="true" threadSafe singleton {
}
}



/**
* Returns the mappings for an index
Expand All @@ -278,25 +278,30 @@ component accessors="true" threadSafe singleton {
var path = arguments.indexName & "/_mapping";
if( !isNull( arguments.field ) ){
path &= "/field/" & arguments.field;
} else if( findNoCase( "*", arguments.indexName ) ){
// if a wild card is present we are only interested in the fields
arguments.field = "*";
path &= "/field/" & arguments.field;
}
var response = variables.nodePool.newRequest( path, "GET" ).send();

if ( response.getStatusCode() != 200 ) {
onResponseFailure( response );
} else {
var mappings = response.json();
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;
}, {} );
? mappings[ indexName ].mappings
: mappings.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

0 comments on commit 83bf2c7

Please sign in to comment.