代码之家  ›  专栏  ›  技术社区  ›  Hammerbot

匹配映射类型,仅目标对象数组

  •  1
  • Hammerbot  · 技术社区  · 7 年前

    我正在尝试为索引创建默认映射。

    我希望我的对象数组被自动检测为 nested 领域。我只希望对象数组作为贴图,而不是常规对象:

    {
      "foo": "bar",
      // someArray should be mapped as a nested type field
      "someArray": [
        {
          "bla": "Blou"
        }
      ],
      // someObject should be mapped as a normal object
      "someObject": {
        "btch": "lasagna"
      }
    }
    

    为了尝试一些东西,我向集群发送了以下内容:

    PUT _template/automatic_nested_object
    {
      "order": 0,
      "template": "*", 
      "mappings": {
        "_default_": { 
          "dynamic_templates": [
            {
              "nested": {
                "match_mapping_type": "object",
                "mapping": {
                  "type": "nested"
                }
              }
            }
          ]
        }
      }
    }
    

    问题是 "match_mapping_type": "object" ,匹配所有对象,而不仅仅是数组,我在文档中找不到任何可以让我有所不同的东西。

    有人知道如何做出这样的改变吗?

    1 回复  |  直到 7 年前
        1
  •  1
  •   Val    7 年前

    PUT _template/automatic_nested_object
    {
      "order": 0,
      "template": "*", 
      "mappings": {
        "doc": {                      <--- note: _default_ deprecated in ES6
          "dynamic_templates": [
            {
              "nested": {
                "match": "*Array",    <--- name clue for nested array
                "mapping": {
                  "type": "nested"
                }
              }
            }
          ]
        }
      }
    }