ElasticSearch-索引模板和索引模式有什么区别 [英] ElasticSearch - what is the difference between an index template and an index pattern

查看:759
本文介绍了ElasticSearch-索引模板和索引模式有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里阅读了我的问题的解释:

I have read an explanation to my question here:

https://discuss.elastic.co/t/whats-the-differece-between-index-pattern-and-index-template/54948

但是,我仍然不了解它们之间的区别.定义索引PATTERN时,它根本不会影响索引的创建吗?另外,如果我创建索引但没有相应的索引模式,会发生什么情况?如何查看用于索引模式的映射,以便知道如何使用Mapping API对其进行更新?

However, I still don't understand the difference. When defining an index PATTERN, does it not affect index creation at all? Also, what happens if I create an index but it doesn't have a corresponding index pattern? How can I see the mapping used for an index pattern so I can know how to use the Mapping API to update it?

在旁注中,文档说您可以通过单击设置"然后单击索引"选项卡来管理索引模式.我正在查看Kibana,但没有看到任何设置标签.我可以通过管理"标签查看索引模式,但那里没有任何设置标签

And on a side note, the docs say you manage the index patterns by clicking the "Settings" and then "Indices" tab. I'm looking at Kibana and I don't see any settings tab. I can view the index patterns through the management tab, but I don't see any settings tab there

推荐答案

索引模板是一种ES功能,用于在匹配名称模式时触发新索引的创建.例如,假设我们创建了以下索引模板:

An index template is an ES feature for triggering the creation of new indexes whenever a name pattern is matched. For instance, let's say we create the following index template:

PUT _template/template_1
{
  "index_patterns": ["foo*"],
  "settings": {
    "number_of_shards": 1
  },
  "mappings": {
    ...
  }
}

如您所见,一旦我们想在名为(例如)foo-44的索引中为文档建立索引,并且该索引不存在,则ES将按顺序使用该模板(设置+映射)自动创建foo-44索引.

As you can see, as soon as we want to index a document inside an index named (e.g.) foo-44 and that index doesn't exist, then that template (settings + mappings) will be used by ES in order to create the foo-44 index automatically.

您可以随时通过简单地如上所述放置新的设置/映射定义来更新索引模板.

You can update an index template at any time by simply PUTting a new settings/mappings definition like above.

索引模式(不要与您在上面看到的index-patterns属性混淆,这是两个完全不同的事物),是一种Kibana功能,用于告诉Kibana组成索引的内容(所有字段,它们的类型等).如果不创建索引模式,那么在Kibana中什么也不会发生,而您只能在Management > Index Patterns中进行此操作.

An index pattern (not to be confounded with the index-patterns property you saw above, those are two totally different things), is a Kibana feature for telling Kibana what makes up an index (all the fields, their types, etc). Nothing can happen in Kibana without creating index patterns, which you can do in Management > Index Patterns.

在ES中创建索引不会在Kibana中创建任何索引模式.同样,在Kibana中创建索引模式不会在ES中创建任何索引.

Creating an index in ES will not create any index pattern in Kibana. Similarly, creating an index pattern in Kibana will not create any index in ES.

Kibana之所以需要索引模式,是因为它需要存储索引映射中可用的各种信息.例如,假设您使用以下映射创建索引:

The reason why Kibana needs an index pattern is because it needs to store different kind of information as it available in an index mapping. For instance, let's say you create an index with the following mapping:

PUT my_index
{
  "mappings": {
    "doc": {
      "properties": {
        "timestamp": {
          "type": "date"
        },
        "name": {
          "type": "text"
        }
      }
    }
  }
}

然后,您将在Kibana中创建的相应索引模式将具有以下内容:

Then the corresponding index pattern that you will create in Kibana will have the following content:

GET .kibana/doc/index-pattern:16a98050-a53f-11e8-82ab-af0d48c6ddd8
{
  "type": "index-pattern",
  "updated_at": "2018-08-21T12:38:22.509Z",
  "index-pattern": {
    "title": "my_index*",
    "timeFieldName": "timestamp",
    "fields": """[{"name":"_id","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_index","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"_score","type":"number","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_source","type":"_source","count":0,"scripted":false,"searchable":false,"aggregatable":false,"readFromDocValues":false},{"name":"_type","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":false},{"name":"name","type":"string","count":0,"scripted":false,"searchable":true,"aggregatable":false,"readFromDocValues":false},{"name":"timestamp","type":"date","count":0,"scripted":false,"searchable":true,"aggregatable":true,"readFromDocValues":true}]"""
  }
}

如您所见,Kibana还存储了timestamp字段,即索引模式的名称(,可以跨越多个索引).它还为您定义的每个字段存储各种属性,例如,对于name字段,索引模式包含Kibana需要知道的以下信息:

As you can see, Kibana also stores the timestamp field, the name of the index pattern (which can span several indexes). Also it stores various properties for each field you have defined, for instance, for the name field, the index-pattern contains the following information that Kibana needs to know:

  {
    "name": "name",
    "type": "string",
    "count": 0,
    "scripted": false,
    "searchable": true,
    "aggregatable": false,
    "readFromDocValues": false
  },

这篇关于ElasticSearch-索引模板和索引模式有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆