【问题标题】:configuring similarity algorithms elasticsearch配置相似性算法 elasticsearch
【发布时间】:2015-05-26 14:10:46
【问题描述】:

我想更改弹性搜索的默认相似度算法

我查看了这个链接:https://www.elastic.co/guide/en/elasticsearch/reference/current/index-modules-similarity.html#default-base

但我不知道如何通过rest api或配置文件等设置此配置...

我还查看了此链接: https://www.elastic.co/guide/en/elasticsearch/guide/master/changing-similarities.html

但在此链接中,在构建属性时更改了相似性类型。

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    可以在创建索引时更改索引的默认相似度,如下所示:

    curl -XPUT "http://<server>/<index>" -d '
    {
      "settings": {
        "similarity": {
          "default": { 
            "type": "BM25"
          }
        }
      }
    }
    

    如果索引已经存在,则需要重建,因为目前无法动态更新索引的相似性,如本文所述:open issue

    您可以通过在配置文件中指定 index.similarity.default.type 的值来更改所有索引的默认相似度:

    例子:

    index.similarity.default.type: BM25
    

    【讨论】:

    • 这很好,但我想更改所有新索引的默认弹性搜索设置。
    • hmm 已经在您在原始帖子中链接的文档中.. 我已经更新了答案,但是根据文档推荐的 configure index modules 方法是在创建索引时
    • 您现在可以通过在设置相似度之前关闭现有索引来更新它。我在另一个答案中添加了代码
    【解决方案2】:

    根据 keety 的回答,您现在 (ES6) 可以通过首先关闭现有索引、更改相似度并再次打开它来更改现有索引的相似度。来自docs

    curl -X POST "localhost:9200/index/_close"
    curl -X PUT "localhost:9200/index/_settings" -H 'Content-Type: application/json' -d'
    {
      "index": {
        "similarity": {
          "default": {
            "type": "classic"
          }
        }
      }
    }
    '
    curl -X POST "localhost:9200/index/_open"
    

    【讨论】:

      【解决方案3】:

      Keety 的回答是正确的,但你也可以尝试使用索引模板。

      索引模板允许定义将自动应用于创建的新索引的模板。模板包括设置和映射,以及控制是否将模板应用于创建的索引的简单模式模板。

      在你的情况下:

      curl -XPUT localhost:9200/_template/template_1 -d '
      {
        "template" : "te*",
        "settings": {
          "similarity": {
            "default": { 
              "type": "BM25"
            }
          }
        }
      }'
      

      定义一个名为 template_1 的模板,模板模式为 te*。设置和映射将应用于与 te* 模板匹配的任何索引名称。

      有关索引模板的更多信息,您可以阅读official documentation

      【讨论】:

        猜你喜欢
        • 2012-04-08
        • 1970-01-01
        • 1970-01-01
        • 2014-06-09
        • 2017-03-24
        • 2013-10-25
        • 2011-07-20
        • 2012-03-16
        • 2011-09-17
        相关资源
        最近更新 更多