Elasticsearch动态模板正则表达式匹配

huangapple go评论120阅读模式
英文:

Elasticsearch dynamic_templates regex matching

问题

我想要userId字段在文档中的类型为long。下面的代码仅适用于顶层的userId字段。如何使其在内部对象中生效?

"mappings": {
  "dynamic_templates" : [
    {
      "userId" : {
        "match" : ".*userId.*|userId",
        "match_pattern" : "regex",
        "mapping" : {
          "type" : "long"
        }
      }
    }
  ]
}
英文:

I'd like userId field to be long type where it appears on the document.
Below only works for the top userId field.
How to make it pick up from inner objects?

   "mappings": {

     "dynamic_templates" : [
         {
             "userId" : {
               "match" : ".*userId.*|userId",
               "match_pattern": "regex",
                 "mapping" : {
                   "type" : "long"
                 }
             }
         }
     ]

答案1

得分: 0

根据文档中的说明,您应该尝试使用 path_match

       "mappings": {
    
         "dynamic_templates" : [
             {
                 "userId" : {
                   "path_match" : ".*userId*",
                     "mapping" : {
                       "type" : "long"
                     }
                 }
             }
         ]
英文:

As written in the documentation you should try path_match:

   "mappings": {

     "dynamic_templates" : [
         {
             "userId" : {
               "path_match" : ".*userId*",
                 "mapping" : {
                   "type" : "long"
                 }
             }
         }
     ]

huangapple
  • 本文由 发表于 2020年1月3日 19:48:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578101.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定