我通过 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"
}
}
为了解决这个问题,我将数据重新索引到具有正确数据类型( double )的新索引中,但第二天(每天自动创建索引)创建的索引包含字符串数据类型。
注意:elasticsearch.yml 没有设置(除了集群/节点名称),全部默认
- elaticsearch 的新索引中的映射是如何确定的?
- 如何强制新索引为 Slow_query 字段采用正确的数据类型( double )?
- 有某种索引模板吗?
最佳答案
通过定义index template来控制该特定索引集的映射。在 Elasticsearch 内部。
从default template Logstash is using for ES 5.x indices开始我已经使用了其中的大部分内容,并将您的 slow_query
明确添加为 double
。第二天,当 Logstash 使用该模板名称 my_daily_indices_name-*
创建另一个索引时,Elasticsearch 将看到它与此模板匹配,并使用该定义来创建索引,并将 slow_query
强制执行为 双
。
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/