问题描述
- Elasticsearch检测到的数据类型,具有match_mapping_type.
- 具有匹配和不匹配或match_pattern的字段名称.
- 该字段的完整虚线路径,具有path_match和path_unmatch.
我试图为所有字段使用默认类型 keyword
,而某些具有特定 * Suffix
或 prefix *
的特殊字段可能已指定的类型如下,但最终所有字段意外地都是 keyword
.
I was trying to have a default type keyword
for all fields while some special fields with specific *Suffix
or prefix*
could have specified types as follows, but it turned out all fields will be keyword
in the end unexpectedly.
{
"order": 99,
"index_patterns": [
"xxxx_stats_*"
],
"settings": {
"index": {
"number_of_shards": "6",
"number_of_replicas": "1"
}
},
"mappings": {
"_doc": {
"dynamic": true,
"_source": {
"enabled": true
},
"dynamic_templates": [
{
"strings": {
"match_mapping_type": "*",
"unmatch": [
"*Time",
"*At",
"is*"
],
"mapping": {
"ignore_above": 256,
"null_value": "NULL",
"type": "keyword"
}
}
},
{
"timeSuffix": {
"match_mapping_type": "*",
"match": [
"*Time",
"*At"
],
"mapping": {
"type": "long"
}
}
},
{
"isPrefix": {
"match_mapping_type": "*",
"match": "is*",
"mapping": {
"type": "boolean"
}
}
}
],
"date_detection": false,
"numeric_detection": true
}
},
"aliases": {
"{index}-alias": {
}
}
}
推荐答案
AFAIK match
和 unmatch
不能是数组,只能是字符串或正则表达式.所以试试这个:
AFAIK match
and unmatch
cannot be arrays, only strings or regexes. So try this:
{
"dynamic_templates":[
{
"timeSuffix":{
"match_mapping_type":"*",
"match_pattern":"regex",
"match":"^(.*Time)|(.*At)$",
"mapping":{
"type":"long"
}
}
},
{
"isPrefix":{
"match_mapping_type":"*",
"match":"is*",
"mapping":{
"type":"boolean"
}
}
},
{
"strings":{
"match_mapping_type":"*",
"mapping":{
"ignore_above":256,
"null_value":"NULL",
"type":"keyword"
}
}
}
]
}
我还发现,当您将 strings
移到底部时,上面的2个映射将首先得到解决.否则,由于每个段都包含 match_mapping_type:" *"
,因此将应用第一个匹配段.此问题可能相关.
I also find that when you move strings
to the bottom, the 2 mappings above will be resolved first. Otherwise, since every segment includes match_mapping_type":"*"
, the first matching segment will apply. This issue may be related.
这篇关于动态模板是否支持默认类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!