Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,9 @@ public void testApiNamingConventions() throws Exception {
"indices.exists_type",
"indices.get_upgrade",
"indices.put_alias",
"render_search_template",
"scripts_painless_execute",
"render_search_template"
"indices.reload_search_analyzers"
};
//These API are not required for high-level client feature completeness
String[] notRequiredApi = new String[] {
Expand Down
43 changes: 43 additions & 0 deletions docs/reference/analysis/tokenfilters/synonym-tokenfilter.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ appear before it in the chain.
Additional settings are:

* `expand` (defaults to `true`).
* `updateable` (defaults to false). If `true`, this marks the filter to be updateable using the
<<indices-reload-analyzers,analyzer reload API>>, but it will also restrict the filter to only be usable in
<<search-analyzer,search analyzers>>.
* `lenient` (defaults to `false`). If `true` ignores exceptions while parsing the synonym configuration. It is important
to note that only those synonym rules which cannot get parsed are ignored. For instance consider the following request:



[source,js]
--------------------------------------------------
Expand Down Expand Up @@ -181,3 +186,41 @@ error.
If you need to build analyzers that include both multi-token filters and synonym
filters, consider using the <<analysis-multiplexer-tokenfilter,multiplexer>> filter,
with the multi-token filters in one branch and the synonym filter in the other.

=== Updateability of search time synonyms

Synonym filters that are used in <<search-analyzer,search analyzers>> can be marked
as updateable using the `updateable` flag:

[source,js]
--------------------------------------------------
PUT /test_index
{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"synonym" : {
"tokenizer" : "whitespace",
"filter" : ["synonym"]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/synonym.txt",
"updateable" : true
}
}
}
}
}
}
--------------------------------------------------
// CONSOLE

Using the <<indices-reload-analyzers,analyzer reload API>>, you can trigger reloading of the
synonym definition. The contents of the configured synonyms file will be reloaded and the
synonyms definition the filter uses will be updated.

NOTE: Trying to use the above analyzer as an index analyzer will result in an error.
3 changes: 3 additions & 0 deletions docs/reference/indices.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ index settings, aliases, mappings, and index templates.
* <<indices-refresh>>
* <<indices-flush>>
* <<indices-forcemerge>>
* <<indices-reload-analyzers>>

--

Expand Down Expand Up @@ -109,3 +110,5 @@ include::indices/refresh.asciidoc[]

include::indices/forcemerge.asciidoc[]

include::indices/reload-analyzers.asciidoc[]

65 changes: 65 additions & 0 deletions docs/reference/indices/reload-analyzers.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[[indices-reload-analyzers]]
== Reload Search Analyzers

experimental[]

Reloads search analyzers and its resources.

The `_reload_search_analyzers` API can be run on one or more indices and will
reload all search analyzers that contain components that were marked as
updateable when they were created, such as
<<analysis-synonym-tokenfilter,synonym token filters>>:

[source,js]
--------------------------------------------------
PUT /test_index
{
"settings": {
"index" : {
"analysis" : {
"analyzer" : {
"my_synonyms" : {
"tokenizer" : "whitespace",
"filter" : ["synonym"]
}
},
"filter" : {
"synonym" : {
"type" : "synonym",
"synonyms_path" : "analysis/synonym.txt",
"updateable" : true <1>
}
}
}
}
},
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer" : "standard",
"search_analyzer": "my_synonyms" <2>
}
}
}
}
--------------------------------------------------
// CONSOLE

<1> Mark the synonym filter as updateable.
<2> Synonym analyzer is usable as a search_analyzer.

Calling the `_reload_search_analyzers` endpoint will now trigger reloading of the
synonyms from the configured "synonym.txt" file.

NOTE: Reloading will happen on every node the index has shards, so its important
to update the synonym file contents on every data node (even the ones that don't currently
hold shard copies; shards might be relocated there in the future) before calling
reload to ensure the new state of the file is reflected everywhere in the cluster.

[source,js]
--------------------------------------------------
POST /my_index/_reload_search_analyzers
--------------------------------------------------
// CONSOLE
// TEST[s/^/PUT my_index\n/]
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"indices.reload_search_analyzers": {
"documentation": "https://www.elastic.co/guide/en/elasticsearch/reference/master/indices-reload-analyzers.html",
"stability": "experimental",
"methods": ["GET", "POST"],
"url": {
"paths": ["/{index}/_reload_search_analyzers"],
"parts": {
"index": {
"type": "list",
"description" : "A comma-separated list of index names to reload analyzers for"
}
},
"params": {
"ignore_unavailable": {
"type" : "boolean",
"description" : "Whether specified concrete indices should be ignored when unavailable (missing or closed)"
},
"allow_no_indices": {
"type" : "boolean",
"description" : "Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified)"
},
"expand_wildcards": {
"type" : "enum",
"options" : ["open","closed","none","all"],
"default" : "open",
"description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both."
}
}
},
"body": null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@
import org.elasticsearch.rest.action.admin.indices.RestPutMappingAction;
import org.elasticsearch.rest.action.admin.indices.RestRecoveryAction;
import org.elasticsearch.rest.action.admin.indices.RestRefreshAction;
import org.elasticsearch.rest.action.admin.indices.RestReloadAnalyzersAction;
import org.elasticsearch.rest.action.admin.indices.RestResizeHandler;
import org.elasticsearch.rest.action.admin.indices.RestRolloverIndexAction;
import org.elasticsearch.rest.action.admin.indices.RestSyncedFlushAction;
Expand Down Expand Up @@ -608,6 +609,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
registerHandler.accept(new RestGetFieldMappingAction(settings, restController));

registerHandler.accept(new RestRefreshAction(settings, restController));
registerHandler.accept(new RestReloadAnalyzersAction(settings, restController));
registerHandler.accept(new RestFlushAction(settings, restController));
registerHandler.accept(new RestSyncedFlushAction(settings, restController));
registerHandler.accept(new RestForceMergeAction(settings, restController));
Expand Down