Search code examples
elasticsearchelasticsearch-mappingelasticsearch-7

Elasticsearch Dynamic Template Mapping


I'm using Elasticsearch version 7.1 and trying to use Dynamic Template mapping, but can't seem to get it to work. The index accepts my mapping and data loads successfully, but the data is not being indexed according to the mapping I've provided which makes me suspect that I have an error in my mapping.

Here's a simplified version of a document I'm trying to index:

{
    "id": "foo",
    "breadcrumb": {
        "en-US": [
            {
                "name": "one",
                "url": "/path/1"
            },
            {
                "name": "two",
                "url": "/path/2"
            }
        ],
        "es-ES": [
            {
                "name": "uno",
                "url": "/path/1"
            },
            {
                "name": "dos",
                "url": "/path/2"
            }
        ]
    }
}

And here's a simplified version of the mapping:

{
    "dynamic": "false",
    "properties": {
        "id": {"type": "keyword"}
    },
    "dynamic_templates": [
        {
            "breadcrumb_template": {
                "path_match": "breadcrumb.*",
                "match_mapping_type": "object",
                "mapping": {
                    "type": "nested",
                    "properties": {
                        "url": {"type": "keyword"},
                        "name": {"type": "keyword"}
                    }
                }
            }
        }
    ]
}

I know I could map this explicitly but I would be repeating the same structure for every different key under "breadcrumb" and I'd prefer to avoid that.


Solution

  • dynamic: false it's not working with dynamic_templates. Fields are saved and appears in the _source, but are not searchable. If you add breadcrumb field with dynamic: true in the properties it should be ok.

    "properties": {
        "id": {"type": "keyword"},
        "breadcrumb": {"type": "object", "dynamic": true}
    }