【问题标题】:Altering dynamic mapping Elasticsearch 5.3改变动态映射 Elasticsearch 5.3
【发布时间】:2017-08-30 02:36:27
【问题描述】:

我的应用程序中的许多字符串字段需要在 elasticsearch 5.3 中动态映射。所有以 id 或 ids 结尾的新字段都应该由 elastic 自动映射和索引:

 "_my_propertyId": 
 {
    "type": "keyword"
 }

我为这样的索引/类型定义了一个动态模板

  "mappings": {
     "my_type": {
        "dynamic_templates": [
           {
              "id_as_keywords": {
                 "match": "*id|*Id|*Ids",
                 "match_mapping_type": "string",
                 "mapping": {
                    "type": "keyword"
                 }
              }
           }
        ]

然而,elastic 仍然会创建如下属性:

       "_someIds": {
          "type": "text",
          "fields": {
             "keyword": {
                "type": "keyword",
                "ignore_above": 256
             }
          }
       }

我不确定我做错了什么,或者为什么这是现在动态字符串字段的默认映射。但是,我需要能够动态地将所有以 id 或 ids 结尾的属性映射为关键字,而不需要 ignore_above 和完全索引,以便我可以使用 searchAPI 搜索它们。想法?为什么现在这是默认的字符串映射(我理解关键字/文本的介绍,但仍然如此)?

更新

找到一篇关于这些默认设置的好文章:

Strings

【问题讨论】:

    标签: java elasticsearch mapping


    【解决方案1】:

    您可以使用match_pattern 参数来更好地控制match 参数。在下面找到更新的动态模板:

    "dynamic_templates": [
              {
                "id_as_keywords": {
                  "match_mapping_type": "string",
                  "match_pattern": "regex",
                  "match": ".*(id|Id|Ids)",
                  "mapping": {
                    "type": "keyword"
                  }
                }
              }
            ]
    

    你可以阅读更多关于match_patternhere的信息。

    【讨论】:

    • 反响很好。让我试试看。
    • 完美运行!谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-11-25
    • 2014-05-28
    • 2021-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多