Elasticsearch Index templates


 

Index templates 有2种:

component templates 可重用的构建块,用于配置settings, mappings, and aliases。虽然可以使用组件模板构造索引模板,但它们不会直接应用于一组索引。

Index templates 索引模板可以包含component templates的集合,也可以直接指定settings, mappings, and aliases。

 

以下条件适用于 index templates:

  • Composable templates 优先于 legacy templates(旧的模板方式). 如果没有composable template匹配,  legacy template 将被应用.
  • 如果index的settings是配置了的,那么settings的优先级高于index template 和 component templates.
  • 如果一个新的data stream 或 index 可以匹配多个index template, 将选择优先级最高的index template.

Elasticsearch内置了以下模板,他们用于Elasticsearch自身,优先级是100:

logs-*-*
metrics-*-*
synthetics-*-*

为了避免冲突,最好把自定义的模板跟内置模板的命名区分开。

以下创建2个component templates

PUT _component_template/component_template1 { "template": { "mappings": { "properties": { "@timestamp": { "type": "date" } } } } } PUT _component_template/runtime_component_template { "template": { "mappings": { "runtime": {  "day_of_week": { "type": "keyword", "script": { "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))" } } } } } }

以下创建Index templates 并把component_template1, runtime_component_template作为组件

PUT _index_template/template_1 { "index_patterns": ["te*", "bar*"], "template": { "settings": { "number_of_shards": 1 }, "mappings": { "_source": { "enabled": true }, "properties": { "host_name": { "type": "keyword" }, "created_at": { "type": "date", "format": "EEE MMM dd HH:mm:ss Z yyyy" } } }, "aliases": { "mydata": { } } }, "priority": 500, "composed_of": ["component_template1", "runtime_component_template"],  "version": 3, "_meta": { "description": "my custom" } }

 

 

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM