How to dynamically change synonyms for ElasticSearch

后端 未结 5 1391
执念已碎
执念已碎 2021-02-06 05:22

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

相关标签:
5条回答
  • 2021-02-06 05:42

    You've flipped mysynonymfilter and synonym in your final curl command. The type should be synonym.

    0 讨论(0)
  • 2021-02-06 05:49

    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.

    0 讨论(0)
  • 2021-02-06 05:57

    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.

    0 讨论(0)
  • 2021-02-06 06:03

    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

    0 讨论(0)
  • 2021-02-06 06:04

    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:

    • Close the index.
    • Update the index settings with the new synonym list. To be safe, I am updating all of the analyzers, tokenizers and char filters for the index (not just the synonym filter) - but I am not sure that is necessary.
    • Open the index.
    0 讨论(0)
提交回复
热议问题