My synonyms are stored in a database and, when the synonyms are changed in the database, I want to update any values in the index which may be changed as a result of the synonym
You've flipped mysynonymfilter
and synonym
in your final curl command. The type should be synonym
.
There is a project for reloading the synonym file lindstromhenrik/elasticsearch-analysis-file-watcher-synonym Although I don't know if it works in the latest versions. Maybe you can start by using the plugin and expanding synonyms at query time, since at query time you will have all the synonyms updated instead of reindexing documents that you guess that should be updated because of changes in the synonyms file.
I know this is an old thread but as of ES 7.5 they have added a new feature to update synonyms. Have a look at their documentation.
You need to issue a POST api like this
POST /twitter/_reload_search_analyzers
This would reload all the search analyzers, also ensure that the synonym token filter have the updateable
flag set to true
like this "updatedable": true
.
PS: This feature is part of X-Pack and comes under the basic license which is free.
I know this is an old thread, but in case it helps someone. The answer can be found here:
If you specify stopwords inline with the stopwords parameter, your only option is to close the index and update the analyzer configuration with the update index settings API, then reopen the index.
Updating stopwords is easier if you specify them in a file with the stopwords_path parameter. You can just update the file (on every node in the cluster) and then force the analyzers to be re-created by either of these actions:
Closing and reopening the index (see open/close index), or Restarting each node in the cluster, one by one
It turns out that you can tell ElasticSearch programmatically that the synonyms have changed. That is, it is not necessary to update the synonym file. Here's the basic steps that are necessary: