如何动态更改ElasticSearch的同义词 [英] How to dynamically change synonyms for ElasticSearch

查看:428
本文介绍了如何动态更改ElasticSearch的同义词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的同义词存储在数据库中,当数据库中的同义词更改时,我想更新索引中由于同义词更改而可能更改的所有值。

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 change.

我可以想到两个部分。一,找出要重新编制索引的文件。第二,弄清楚如何告诉ElasticSearch同义词已更改。我正在为第二个问题而苦苦挣扎-告诉ElasticSearch同义词已经更改。

There are two parts to this that I can think of. One, figuring out which documents to re-index. Two, figuring out how to tell ElasticSearch that the synonyms have changed. I am struggling with the 2nd one - telling ElasticSearch that the synonyms have changed.

有人问了类似的问题-请参见动态更改Elasticsearch同义词-但是从阅读该问题的答案后,我仍无法弄清我的需要。

A similar question has been asked - see Change dynamically elasticsearch synonyms - but from reading the answers in that issue, I have not been able to figure out what I need.

当前,我的配置文件如下所示:

Currently, my configuration file looks something like the following:

index :
  analysis :
    analyzer :
      myanalyzer :
        filter: [standard, mysynonymfilter]
filter :
  mysynonymfilter :      
    type : synonym
    synonyms : synonyms.txt
    ignore_case : false
    expand : true
    format : solr

我的想法是执行以下操作:

My idea was to do something like the following:

curl -XPUT 'http://127.0.0.1:9200/foo/_settings'  -d '
{
    "filter" : {
        "synonym" : {
            "type" : "mysynonymfilter",
            "synonyms" : [
                "cosmos, universe"
            ] 
        }
    }
}
'

但这似乎并没有满足我的要求。也就是说,据我所知,索引设置不会得到更新。

but that doesn't seem to do what I want. That is, the index settings do not get updated as far as I can tell.

我正在尝试做的可能吗?如果是这样,知道我在做什么错了吗?

Is what I am trying to do possible? And if so, any idea what I am doing wrong?

此外,我相当确定我可以通过更新同义词文件来使它正常工作(如果我必须使用文件),但这有点复杂,我想避免。

Also, I am fairly sure I could get this to work by updating the synonym file (if I have to use a file), but that's a bit more complicated and something I'd like to avoid.

感谢您的帮助,
Eric

Thanks for your help, Eric

推荐答案

事实证明,您可以通过编程方式告诉ElasticSearch同义词已更改。即,没有必要更新同义词文件。这是必需的基本步骤:

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:


  • 关闭索引。

  • 使用以下命令更新索引设置新的同义词列表。为了安全起见,我将更新索引的所有分析器,令牌生成器和char过滤器(而不仅仅是同义词过滤器)-但我不确定这是必要的。

  • 打开索引。

这篇关于如何动态更改ElasticSearch的同义词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆