gpt4 book ai didi

elasticsearch - 如何在Elasticsearch的新索引中确定映射

转载 作者:行者123 更新时间:2023-12-02 22:23:07 24 4
gpt4 key购买 nike

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

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

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

GET indexName / _mapping 输出
      "slow_query": {
"type": "text",
"norms": false,
"fields": {
"keyword": {
"type": "keyword"
}
}

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

注意: elasticsearc.yml没有设置(除了集群/节点名称),所有默认设置
  • 如何在elaticsearch的新索引中确定映射?
  • 如何强制新索引为slow_query字段采用正确的数据类型( double )?
  • 是否有某种索引模板?
  • 最佳答案

    通过在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"
    }
    }
    }
    }
    }

    关于elasticsearch - 如何在Elasticsearch的新索引中确定映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44196540/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com