简体   繁体   中英

ElasticSearch index template versioning

My application creates an index template on ElasticSearch. Later on, the application is updated and needs to update the index template to support new fields.

  1. Is there a way to set a some identifier for the index template (except its name which is always the same), such that my app can compare these values between the app version and the deployed version? (unique ID / ETag / anything else)

  2. Alternatively, if I can't detect a difference: What is the cost of modifying the index template multiple times, mostly modifications that perform no actual change?

  3. Can I find for an index which template it uses (and which version of it, if such ability exists)?

Thanks.

When creating an index template, you can use the mapping metadata to store the extra info needed to know from which version of the application the mapping was created.

PUT _template/my_template
{
  "template" : "logstash-*",
  "mappings" : {
      "logs" : {
        "_meta" : {
          "product" : "my_product",
          "version" : "1.0.1"
        },
        "_source" : {"enabled" : "true"},
        "properties" : {
        }
      }
  }
}

Then query for existing indices to find the index last created and then get its mappings.

GET logstash-2015.10.08/_mapping

You'll find the mappings and the metadata inside.

This can be useful to store the version of the product the mapping correlates to.

  1. Yes, you can use ElasticSearch's template versioning feature by including "version": <version number> in your template.

Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#versioning-templates

  1. There's no cost in modifying the template, as it's just stored in ES's database {read as 'storage used by ES'}. The only difference is that updates to the templates will only be applicable to the new index being created and won't be applied to the existing indices.

I've solved for this before by using version numbers, build IDs or time stamps as part of the index name (and using index aliases to point to the relevant index for each application).

See this post for a more detailed example: https://www.elastic.co/blog/changing-mapping-with-zero-downtime

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