Skip to content

Commit

Permalink
Merge pull request #135 from michaelborn/feat/open-close-index
Browse files Browse the repository at this point in the history
Add openIndex, closeIndex methods
  • Loading branch information
jclausen authored May 7, 2024
2 parents e28d39f + 260d63e commit cbb326f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
23 changes: 23 additions & 0 deletions docs/Indices/Managing-Indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,15 @@ indexBuilder.patch(
```

## Retrieving Settings for an Index

To retreive a list of all settings for an index you may use the `getSettings` method on the client.

```js
var indexSettings = getInstance( "Client@CBElasticsearch" ).getSettings( "bookshop" )
```

## Retrieving Mappings for an Index

To retreive a list of the configured mappings for an index you may use the `getMappings` method on the client.

```js
Expand Down Expand Up @@ -242,6 +245,26 @@ getInstance( "Client@CBElasticsearch" )

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.

## Opening or Closing an Index

Certain index-level settings can not be applied while the index is open. To solve this, CBElasticsearch offers the `.closeIndex()` and `.openIndex()` methods:

```js
var mappings = getInstance( "Client@CBElasticsearch" ).closeIndex( "reviews" );

// apply settings...

var mappings = getInstance( "Client@CBElasticsearch" ).openIndex( "reviews" );
```

Each of these methods accepts a struct of name/value (simple values only) arguments to pass in the query string:

```js
var mappings = getInstance( "Client@CBElasticsearch" ).closeIndex( "reviews", { "ignore_unavailable" : true } );
```

See [the Elasticsearch "Close Index" documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-close.html) for more information.

## Deleting an Index

All good things must come to an end, eh? You can use `Client.deleteIndex()` to delete an existing index:
Expand Down
56 changes: 56 additions & 0 deletions models/io/HyperClient.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,62 @@ component accessors="true" threadSafe singleton {
.json();
}

/**
* Open the given index/indices.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-open-close.html
*
* @indexName string|array Index name or alias. Can accept an array of index/alias names, as well as wildcard expressions or `_all`.
* @params struct Struct of query parameters to influence the request. For example: `{ "expand_wildcards" : "none" }
*/
function openIndex( required any indexName, any params ){
var requestBuilder = getNodePool()
.newRequest( "#arrayToList( arguments.indexName )#/_open", "POST" )
.asJSON();

if ( structKeyExists( arguments, "params" ) ) {
parseParams( arguments.params ).each( function( param ){
requestBuilder.setQueryParam( param.name, param.value );
} );
}

var response = requestBuilder.send();

if ( response.getStatusCode() != 200 ) {
onResponseFailure( response );
} else {
return response.json();
}
}

/**
* Close the given index/indices.
*
* @see https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-close.html
*
* @indexName string|array Index name or alias. Can accept an array of index/alias names, as well as wildcard expressions or `_all`.
* @params struct Struct of query parameters to influence the request. For example: `{ "expand_wildcards" : "none" }
*/
function closeIndex( required any indexName, any params ){
var requestBuilder = getNodePool()
.newRequest( "#arrayToList( arguments.indexName )#/_close", "POST" )
.asJSON();

if ( structKeyExists( arguments, "params" ) ) {
parseParams( arguments.params ).each( function( param ){
requestBuilder.setQueryParam( param.name, param.value );
} );
}

var response = requestBuilder.send();

if ( response.getStatusCode() != 200 ) {
onResponseFailure( response );
} else {
return response.json();
}
}

/**
* Request a vector of terms for the given index, document or document ID, and field names
*
Expand Down

0 comments on commit cbb326f

Please sign in to comment.