【问题标题】:Elasticsearch dynamic template for all specific properties所有特定属性的 Elasticsearch 动态模板
【发布时间】:2020-11-02 19:55:52
【问题描述】:

我的数据结构是这样的:

{ field: xxx, 
  field2: xxx, 
  attrs: { 
     field3: xxx, 
     field4: xxx, 
     var: { field5: xxx, 
            field6: xxx
     } 
  }
}

我不知道var 中的属性名称,我可以使用动态映射(以及如何)使每个属性仅在 attrs.var.XXX 中可搜索(设置索引:true)?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    您可以使用以下内容:

    PUT unknown_paths
    {
      "mappings": {
        "dynamic_templates": [
          {
            "stored_attrs_vars": {
              "path_match": "attrs.*.*",
              "mapping": {
                "index": true
              }
            }
          },
          {
            "no_index": {
              "path_match": "*",
              "unmatch": "attrs.*.*",
              "mapping": {
                "index": false
              }
            }
          }
          
        ]
      }
    }
    

    请注意,如果没有实际的字段类型,ES 仍会为您猜测。所以即使你不知道attrs.var的名字,你也应该知道field5 and 6的类型吧?

    【讨论】:

    • 他知道attrs.var,所以我猜你可以用attrs.var.*代替attrs.*.*,他不知道attrs.var里面的字段名称
    • 无法反驳。
    • 我什至不知道 attrs.var 的名称。只有一些我需要映射的地方。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2012-11-15
    • 1970-01-01
    • 2023-01-08
    • 1970-01-01
    • 2020-03-03
    • 1970-01-01
    相关资源
    最近更新 更多