简体   繁体   中英

elasticsearch 5.0 and index template

I'm moving from elasticsearch 2.x to elasticsearch 5.0. During startup elasticsearch tells me I can no longer define index properties in the 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. 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

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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