【问题标题】:How are mappings determined in new indices in elaticsearchelasticsearch中的新索引如何确定映射
【发布时间】:2017-05-26 08:00:47
【问题描述】:

我正在通过 logstash 添加一个新字段,如下所示:

 if [message] =~ /.+SLOW QUERY/ {
    grok {
        match => ["message", "SLOW QUERY.+%{NUMBER:slow_query:double}ms"]
    }
 }

但该字段是使用类型字符串创建的。

获取 indexName/_mapping 输出

      "slow_query": {
        "type": "text",
        "norms": false,
        "fields": {
          "keyword": {
            "type": "keyword"
          }
        }

为了解决这个问题,我将数据重新索引到具有正确数据类型(双精度)的新索引中,但第二天(每天自动创建索引)创建的索引包含字符串数据类型。

注意: elasticsearc.yml 没有设置(除了集群/节点名称),全部默认

  • 如何在 elaticsearch 的新索引中确定映射?
  • 如何强制新索引为 slow_query 字段采用正确的数据类型(双精度)?
  • 是否有某种索引模板?

【问题讨论】:

    标签: elasticsearch logstash elastic-stack


    【解决方案1】:

    通过在 Elasticsearch 中定义 index template 来控制特定索引集的映射。

    default template Logstash is using for ES 5.x indices 开始,我已经使用了大部分,并将您的slow_query 明确添加为double。第二天,当 Logstash 将使用该模板名称 my_daily_indices_name-* 创建另一个索引时,Elasticsearch 将看到它与此模板匹配,并使用该定义创建索引并将 slow_query 强制为 double

    PUT /_template/my_template
    {
      "template": "my_daily_indices_name-*",
        "mappings" : {
        "_default_" : {
          "_all" : {"enabled" : true, "norms" : false},
          "dynamic_templates" : [ {
            "message_field" : {
              "path_match" : "message",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "text",
                "norms" : false
              }
            }
          }, {
            "string_fields" : {
              "match" : "*",
              "match_mapping_type" : "string",
              "mapping" : {
                "type" : "text", "norms" : false,
                "fields" : {
                  "keyword" : { "type": "keyword" }
                }
              }
            }
          } ],
          "properties" : {
            "@timestamp": { "type": "date", "include_in_all": false },
            "@version": { "type": "keyword", "include_in_all": false },
            "geoip"  : {
              "dynamic": true,
              "properties" : {
                "ip": { "type": "ip" },
                "location" : { "type" : "geo_point" },
                "latitude" : { "type" : "half_float" },
                "longitude" : { "type" : "half_float" }
              }
            },
            "slow_query": {
              "type": "double"
            }
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-03-11
      • 2019-04-16
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-23
      相关资源
      最近更新 更多