Dor Rotman
Dor Rotman

Reputation: 1551

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.

Upvotes: 3

Views: 5234

Answers (3)

avp
avp

Reputation: 3330

  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.

Upvotes: 2

Dor Rotman
Dor Rotman

Reputation: 1551

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.

Upvotes: 2

Peter Dixon-Moses
Peter Dixon-Moses

Reputation: 3209

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

Upvotes: 0

Related Questions