【问题标题】:Can I use a wildcard when setting dynamic template properties for elasticsearch index templates?为 elasticsearch 索引模板设置动态模板属性时可以使用通配符吗?
【发布时间】:2021-02-15 07:20:24
【问题描述】:

我有一个索引模板,它有一个属性,该属性有一个名为 meta 的动态对象。 我还有一个动态模板规则,它将字符串类型的所有元属性设置为关键字并将它们添加到另一个名为 catch_all 的字段。

有一个特定的属性,extendedDescription,我不想作为关键字添加,我想明确地将它的类型设置为文本。我通过为该设置添加显式设置来做到这一点。

但是,该属性可以出现在我的元对象的不同父属性中,例如在 "meta.none.extendedDescription""meta.it.extendedDescription""meta.en.extendedDescription" 中。

这是我现在正在使用的,它可以工作,但你可以看到我必须为每次出现的扩展描述“硬编码”设置。 (并且可以很好地使用我已经拥有的动态模板)

{
  "order": 0,
  "index_patterns": [
    "my-poi-*"
  ],
  "settings": {},
  "mappings": {
    "doc": {
      "dynamic_templates": [
        {
          "string_fields_all": {
            "match_mapping_type": "string",
            "match": "*",
            "mapping": {
              "analyzer": "analyzer_keyword",
              "type": "keyword",
              "copy_to": "catch_all"
            }
          }
        }
      ],
      "dynamic": false,
      "properties": {
        "name": {
          "type": "keyword",
          "copy_to": "catch_all"
        },
        "meta": {
          "type": "object",
          "dynamic": true,
          "properties": {
            "none": {
              "type": "object",
              "dynamic": true,
              "properties": {
                "extendedDescription": {
                  "type": "text",
                  "index": false
                }
              }
            },
            "it": {
              "type": "object",
              "dynamic": true,
              "properties": {
                "extendedDescription": {
                  "type": "text",
                  "index": false
                }
              }
            },
            "en": {
              "type": "object",
              "dynamic": true,
              "properties": {
                "extendedDescription": {
                  "type": "text",
                  "index": false
                }
              }
            }
          }
        },
        "catch_all": {
          "type": "text"
        }
      }
    }
  },
  "aliases": {}
}

有没有一种方法可以使用通配符或规则来允许将此属性设置为文本,无论它出现在我的元对象中的什么位置? (它总是有"meta.{some-lang-code}.extendedDescription"的模式

我试过了,但没用:

"meta": {
  "type": "object",
  "dynamic": true,
  "properties": {
    "*.extendedDescription": {
      "type": "text",
          "index": false                            
  }
},

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    我认为你不能在顶级 b/c 上设置 dynamic: false 时这样做,这样你就可以提前防止任何未知的 meta.* 对象。我在这里可能是错的,但我认为确实如此。

    您可以尝试使用path_match

    {
      "mappings": {
        "doc": {
          "dynamic_templates": [
            {
              "meta": {
                "path_match": "meta.*",          <--
                "mapping": {
                  "type": "object",
                  "dynamic": true,
                  "properties": {
                    "extendedDescription": {
                      "type": "text",
                      "index": false
                    }
                  }
                }
              }
            },
            {
              "string_fields_all": {
                "match_mapping_type": "string",
                "match": "*",
                "mapping": {
                  "analyzer": "analyzer_keyword",
                  "type": "keyword",
                  "copy_to": "catch_all"
                }
              }
            }
          ],
          "dynamic": true,                     <--
          "properties": {
            "name": {
              "type": "keyword",
              "copy_to": "catch_all"
            },
            "catch_all": {
              "type": "text"
            }
          }
        }
      }
    }
    

    【讨论】:

    • 这个@darren运气好吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-23
    • 2012-08-21
    • 1970-01-01
    相关资源
    最近更新 更多