numeric_detection 和dynamic_templates之间的优先级



根据dynamic_templates中的顺序有优先级,但是numeric_detectiondynamic_templates之间是否有优先级?

模板按顺序处理 — 第一个匹配的模板获胜。

可以肯定地说dynamic_templates的优先级低于(或更高)numeric_detection吗?

numeric_detection不是模板。这是field mapping.当您指定多个templates时,将按顺序处理它们。

我尝试了以下练习来确认numeric detectiondynamic templates之间的优先级。

映射:

{
"dynamic_templates": [
{
"integers": {
"match_mapping_type": "long",
"mapping": {
"type": "short"
}
}
}
],
"numeric_detection": true
}

如果它检测到一个数字,它有两个选项。一个设置为long,通过启用numeric_Detection说,另一个如果long将其设置为short,则由dynamic_templates处理。

然后索引以下数据

{
"whoami":"25"
}

然后我检查了映射。我找到了这个。

"properties": {
"whoami": {
"type": "short"
}
}

然后,我尝试禁用dynamic field映射。

{
"dynamic_templates": [
{
"integers": {
"match_mapping_type": "long",
"mapping": {
"type": "short"
}
}
}
],
"numeric_detection": false
}

这一次,whoami存储为text.

所以优先级如下。

  1. 动态字段映射 - 最高
  2. 动态模板映射 - 最低

dynamic field标识必须应用的规则。一旦规则被dynamic field mapping应用,那么自定义规则就会被应用dynamic template mapping

感谢 Gibbs 的帮助,我多次阅读了该文档并测试了更多演示。

我认为可以肯定地说,一旦指定了以下条件,dynamic templates就会生效。

  • Elasticsearch 检测到的数据类型,带有 match_mapping_type。
  • 字段的名称,带有"匹配"和"不匹配"或"match_pattern"。
  • 通往田野的完整虚线路径,带有path_match和path_unmatch。

虽然第一个条件让我感到困惑(吉布斯帮助消除了这种困惑),但"数据类型"应该是field mapping之后的类型。

至于字段映射规则,我们可以在动态字段映射中检查详细信息。

  • 字符串
日期字段(如果值通过

日期检测)、双精度或长字段(如果值通过数字检测)或带有关键字子字段的文本字段。


演示将为我们提供使用match指定动态模板uidkeyword

GET my_index/_mapping
PUT my_index
{
"mappings": {
"numeric_detection": true,
"dynamic_templates": [
{
"strings_as_keywords": {
"match": "uid",
"mapping": {
"type": "keyword",
"ignore_above": 256
}
}
}
]
}
}
POST my_index/_doc/1
{
"uid": "123"
}

最新更新