Reputation: 1551
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.
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)
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?
Can I find for an index which template it uses (and which version of it, if such ability exists)?
Thanks.
Upvotes: 3
Views: 5234
Reputation: 3330
"version": <version number>
in your template. Upvotes: 2
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
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