【问题标题】:Step-by-step guide for creating index?创建索引的分步指南?
【发布时间】:2016-05-03 01:19:24
【问题描述】:

我正在寻找在elasticsearch中创建索引的指南,但它并不像以下给出的指南那么简单:

https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html

我想做的事情似乎很简单,但我似乎无法让它发挥作用。现在,我希望我的索引是每日索引(与默认的 logstash 索引相同)但有一些变化。这些更改包括名称更改和具有特定类型的字段的特定映射。现在我知道我必须在 logstasg 配置的 output-elasticsearch 部分中指定:

index => "name-%{+YYYY.MM.dd}"

我发现的唯一信息是可以基于模板创建索引,我尝试创建模板但仍然没有任何反应。

创建模板我使用了以下内容:

PUT _template/ids
{
"template": "ids-*", 
"order":    0, 
"settings": {
"index": {
  "number_of_shards": 5,
  "number_of_replicas": 1
},
"mappings": {
  "log": {
    "_all": {
      "enabled": true,
      "omit_norms": true
    },
    "properties": {
      "@timestamp": {
        "type": "date",
        "format": "strict_date_optional_time||epoch_millis"
      },
      "@version": {
        "type": "string",
        "index": "not_analyzed"
      },
      "field1": {
        "type": "string",
        "index": "not_analyzed"
      },
      "field2": {
        "type": "string",
        "index": "not_analyzed"
      },

【问题讨论】:

  • 您能否提供更多信息,例如用于index-creationtemplate-creation 的命令?
  • 对于template-creation,我使用了以下命令,其中包含一些设置:PUT _template/ids { "template": "ids-*", "order": 0, "settings": { "index": { "number_of_shards": 5, "number_of_replicas": 1 }, "mappings": {...。如果我运行这个命令,我会得到它被接受的结果,但前进是我卡住的地方。
  • 由于某种原因,我看不到您的完整命令。你能用完整的命令更新你的问题吗?但是,如果您成功创建模板,则可以通过使用模式 ids-* 创建测试索引来测试它,例如 ids-test
  • 我更新了问题。我也尝试了我们的建议,它创建了类似ids-test 的东西。但是我将如何更改它以便它每天创建该索引?
  • ids-test index 是否获得了 index-pattern 中提供的所有设置和映射?

标签: elasticsearch indexing logstash


【解决方案1】:

对于带有“一些变化”的每日索引,最好使用模板。

要检查集群中已经设置了哪些模板,请使用:

GET {es_url}/_template

要为集群设置新模板,请使用:

PUT {es_url}/_template/ids
{
"template": "ids-*", 
"order":    0, 
"settings": {
"index": {
  "number_of_shards": 5,
  "number_of_replicas": 1
},
"mappings": {
  "log": {
    "_all": {
      "enabled": true,
      "omit_norms": true
    },
    "properties": {
      "@timestamp": {
        "type": "date",
        "format": "strict_date_optional_time||epoch_millis"
      },
      "@version": {
        "type": "string",
        "index": "not_analyzed"
      },
      "field1": {
        "type": "string",
        "index": "not_analyzed"
      },
      "field2": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  }
}}}

要删除现有模板,请使用:

DELETE {es_url}/_template/{template_name}

如果您将“ids”模板设置为集群 - 将插入到集群中的任何文档,以使用与“ids-*”匹配的名称(又名“ids-123”、“ids-sheker”、 "ids-2016.05.02") 会得到插入的ids模板的映射。

【讨论】:

  • 谢谢。我试过这个,但没有成功。但这对我来说是个问题,因为没有发送数据,所以没有创建索引。发送一些数据后,模板就起作用了。
猜你喜欢
  • 1970-01-01
  • 2011-08-05
  • 2019-12-20
  • 2016-12-02
  • 1970-01-01
  • 1970-01-01
  • 2013-11-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多