简体   繁体   English

elasticsearch 5.0和索引模板

[英]elasticsearch 5.0 and index template

I'm moving from elasticsearch 2.x to elasticsearch 5.0. 我正在从elasticsearch 2.x迁移到Elasticsearch 5.0。 During startup elasticsearch tells me I can no longer define index properties in the elasticsearch.yml . 在启动过程中,elasticsearch告诉我我无法再在elasticsearch.yml中定义索引属性。 Through the elasticsearch 5.0 documentation I found out I needed to use index templates to set default parameters that were set in the elasticsearch.yml in version 2.x. 通过elasticsearch 5.0文档,我发现我需要使用索引模板来设置在2.x版中的elasticsearch.yml中设置的默认参数。 In my case I had the following setup 就我而言,我有以下设置

index:
  number_of_shards: 1
  number_of_replicas: 1
  similarity:
    default:
      type: BM25
      b:0.0
      k1:1.2
    norm_bm25:
      type: BM25
      b:0.75
      k1:1.2

Using and index template instead, I tried to convert this to 而是使用和索引模板,我尝试将其转换为

curl -XPUT 'http://localhost:9200/_template/template1' -d '{
  "template" : "*",  
  "settings.index.number_of_replicas" : "1",
  "settings.index.number_of_shards" : "1",
  "settings.index.similarity.default.b" : "0.0",
  "settings.index.similarity.default.k1" : "1.2",
  "settings.index.similarity.default.type" : "BM25",
  "settings.index.similarity.norm_bm25.b" : "0.75",
  "settings.index.similarity.norm_bm25.k1" : "1.2",
  "settings.index.similarity.norm_bm25.type" : "BM25"
}'

I'm using elasticsearch.js version 12. and getting the error 我正在使用Elasticsearch.js版本12,并收到错误消息

Error: [illegal_argument_exception] unknown setting [index.similarity]  

which I assume is because I am setting the similarity in the wrong way in the template. 我认为这是因为我在模板中以错误的方式设置了相似性。 My javascript code remains unchanged from the upgrade to elasticsearch 5.0, however, the offending javascript code, resulting in the error is 我的JavaScript代码在升级到Elasticsearch 5.0时保持不变,但是,令人反感的javascript代码导致出现以下错误:

client.indices.create({
  index: indexName,
  body: { settings: { 
          number_of_shards: 1,
          similarity : "norm_bm25"
  } 
},....error stuff)

What is the correct way to correctly convert my elasticsearch.yml to a set of curl operation so that it works in elasticsearch 5.0? 正确地将我的elasticsearch.yml转换为一组curl操作,使其在Elasticsearch 5.0中工作的正确方法是什么?

The correct way to write template is 编写模板的正确方法是

PUT _template/template1
{
  "template": "*",
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 1,
    "index": {
      "similarity": {
        "default": {
          "type": "BM25",
          "b": 0,
          "k": 1.2
        },
        "norm_bm25": {
          "type": "BM25",
          "b": 0.75,
          "k": 1.2
        }
      }
    }
  }
}

You can refer to docs for more info. 您可以参考文档以获取更多信息。 You would copy the same settings dictionary in your javascript code. 您将在javascript代码中复制相同的设置字典。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM