简体   繁体   English

用于嵌套的ElasticSearch动态模板

[英]ElasticSearch Dynamic Template for nested

I try to create dynamic template for a nested object. 我尝试为嵌套对象创建动态模板。

Here is a document to index : 这是要编制索引的文件:

{
    "title": "My title",
    "attributes": {
        "color": {
            "id": 42,
            "label": "red"
        },
        "material": {
            "id": 43,
            "label": "textile"
        }
    }
}

This is the template i tried, without success 这是我尝试过的模板,没有成功

{
  "dynamic": "false",
  "dynamic_templates": [
    {
      "attributes": {
        "path_match": "attributes",
        "mapping": {
          "type": "nested"
        }
      }
    },
    {
      "attributes_nested": {
        "path_match": "attributes.*",
        "mapping": {
          "properties": {
            "id": {
              "type": "integer"
            },
            "value": {
              "type": "string"
            }
          }
        }
      }
    }
  ],
  "properties": {
    "title": {
      "type": "string"
    }
  }
}

I'd like to be able to make aggregations on attributes.color.id, and attributes.material.id 我希望能够对attributes.color.id和attributes.material.id进行聚合

Nevermind, the problem was that i had 没关系,问题是我有

{ "dynamic": false}

The correct mapping is 正确的映射是

{
  "dynamic": "false",
  "dynamic_templates": [
    {
      "attributes_nested": {
        "path_match": "attributes.*",
        "mapping": {
          "properties": {
            "id": {
              "type": "integer"
            },
            "value": {
              "type": "string"
            }
          }
        }
      }
    }
  ],
  "properties": {
    "title": {
      "type": "string"
    },
    "attributes": {
      "type": "nested",
      "dynamic": true
    }
  }
}  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM