如何在弹性搜索的新索引中确定映射
How are mappings determined in new indices in elaticsearch
我正在通过 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没有设置(除了cluster/node名字),全部默认
- 如何在 elaticsearch 的新索引中确定映射?
- 如何强制新索引为 slow_query 字段采用正确的数据类型(双精度)?
- 是否有某种索引模板?
通过在 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"
}
}
}
}
}
我正在通过 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没有设置(除了cluster/node名字),全部默认
- 如何在 elaticsearch 的新索引中确定映射?
- 如何强制新索引为 slow_query 字段采用正确的数据类型(双精度)?
- 是否有某种索引模板?
通过在 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"
}
}
}
}
}