简体   繁体   English

ElasticSearch索引模板版本控制

[英]ElasticSearch index template versioning

My application creates an index template on ElasticSearch. 我的应用程序在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) (唯一ID / ETag /其他)

  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. 是的,您可以通过在模板中包含"version": <version number>来使用ElasticSearch的模板版本控制功能。

Source: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-templates.html#versioning-templates 资料来源: 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'}. 修改模板没有任何成本,因为它只存储在ES的数据库中{读作'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). 我之前通过使用版本号,构建ID或时间戳作为索引名称的一部分(并使用索引别名指向每个应用程序的相关索引)解决了这个问题。

See this post for a more detailed example: https://www.elastic.co/blog/changing-mapping-with-zero-downtime 有关更详细的示例,请参阅此帖子: https//www.elastic.co/blog/changing-mapping-with-zero-downtime

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

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