123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- [[put-synonyms-set]]
- === Create or update synonyms set
- beta::[]
- ++++
- <titleabbrev>Create or update synonyms set</titleabbrev>
- ++++
- Creates or updates a synonyms set.
- [[put-synonyms-set-request]]
- ==== {api-request-title}
- `PUT _synonyms/<synonyms_set>`
- [[put-synonyms-set-prereqs]]
- ==== {api-prereq-title}
- Requires the `manage_search_synonyms` cluster privilege.
- [[put-synonyms-set-path-params]]
- ==== {api-path-parms-title}
- `<synonyms_set>`::
- (Required, string)
- Synonyms set identifier to create.
- This identifier will be used by other <<synonyms-apis>> to manage the synonyms set.
- [[put-synonyms-set-api-request-body]]
- ==== {api-request-body-title}
- `synonyms_set`::
- (Required, array of synonym rules objects)
- The synonym rules definitions for the synonyms set.
- .Properties of `synonyms_set` objects
- [%collapsible%open]
- =====
- `id`::
- (Optional, string)
- The identifier associated to the synonym rule, that can be used to manage individual synonym rules via <<synonym-rules-apis,synonym rules APIs>>.
- In case a synonym rule id is not specified, an identifier will be created automatically by {es}.
- `synonyms`::
- (Required, string)
- The synonym rule. This needs to be in <<_solr_synonyms>> format.
- Some examples are:
- * "i-pod, i pod => ipod",
- * "universe, cosmos"
- =====
- [[put-synonyms-set-example]]
- ==== {api-examples-title}
- The following example creates a new synonyms set called `my-synonyms-set`:
- [source,console]
- ----
- PUT _synonyms/my-synonyms-set
- {
- "synonyms_set": [
- {
- "id": "test-1",
- "synonyms": "hello, hi"
- },
- {
- "synonyms": "bye, goodbye"
- },
- {
- "id": "test-2",
- "synonyms": "test => check"
- }
- ]
- }
- ----
- If any of the synonym rules included is not valid, the API will return an error.
- [source,console]
- ----
- PUT _synonyms/my-synonyms-set
- {
- "synonyms_set": [
- {
- "synonyms": "hello => hi => howdy"
- }
- ]
- }
- ----
- // TEST[catch:bad_request]
- [source,console-result]
- ----
- {
- "error": {
- "root_cause": [
- {
- "type": "action_request_validation_exception",
- "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
- "stack_trace": ...
- }
- ],
- "type": "action_request_validation_exception",
- "reason": "Validation Failed: 1: More than one explicit mapping specified in the same synonyms rule: [hello => hi => howdy];",
- "stack_trace": ...
- },
- "status": 400
- }
- ----
- // TESTRESPONSE[s/"stack_trace": \.\.\./"stack_trace": $body.$_path/]
- [[synonyms-set-analyzer-reloading]]
- ==== Analyzer reloading
- When an existing synonyms set is updated, the <<search-analyzer, search analyzers>> that use the synonyms set are reloaded automatically for all indices.
- This would be equivalent to invoking <<indices-reload-analyzers>> for all indices that use the synonyms set.
- For example, creating an index with a synonyms set and updating it:
- [source,console]
- ----
- PUT _synonyms/my-synonyms-set
- {
- "synonyms_set": [
- {
- "id": "test-1",
- "synonyms": "hello, hi"
- }
- ]
- }
- PUT /test-index
- {
- "settings": {
- "analysis": {
- "filter": {
- "synonyms_filter": {
- "type": "synonym_graph",
- "synonyms_set": "my-synonyms-set",
- "updateable": true
- }
- },
- "analyzer": {
- "my_index_analyzer": {
- "type": "custom",
- "tokenizer": "standard",
- "filter": ["lowercase"]
- },
- "my_search_analyzer": {
- "type": "custom",
- "tokenizer": "standard",
- "filter": ["lowercase", "synonyms_filter"]
- }
- }
- }
- },
- "mappings": {
- "properties": {
- "title": {
- "type": "text",
- "analyzer": "my_index_analyzer",
- "search_analyzer": "my_search_analyzer"
- }
- }
- }
- }
- PUT _synonyms/my-synonyms-set
- {
- "synonyms_set": [
- {
- "id": "test-1",
- "synonyms": "hello, hi, howdy"
- }
- ]
- }
- ----
- The reloading result is included as part of the response:
- [source,console-result]
- ----
- {
- "result": "updated",
- "reload_analyzers_details": {
- "_shards": {
- "total": 2,
- "successful": 1,
- "failed": 0
- },
- "reload_details": [
- {
- "index": "test-index",
- "reloaded_analyzers": [
- "my_search_analyzer"
- ],
- "reloaded_node_ids": [
- "1wYFZzq8Sxeu_Jvt9mlbkg"
- ]
- }
- ]
- }
- }
- ----
- // TESTRESPONSE[s/1wYFZzq8Sxeu_Jvt9mlbkg/$body.reload_analyzers_details.reload_details.0.reloaded_node_ids.0/]
|