简体   繁体   English

Elasticsearch 动态模板映射

[英]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.我正在使用 Elasticsearch 7.1 版并尝试使用动态模板映射,但似乎无法使其正常工作。 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.我知道我可以明确地映射它,但我会为“面包屑”下的每个不同的键重复相同的结构,我宁愿避免这种情况。

dynamic: false it's not working with dynamic_templates. dynamic: false它不适用于 dynamic_templates。 Fields are saved and appears in the _source , but are not searchable.字段被保存并出现在_source ,但不可搜索。 If you add breadcrumb field with dynamic: true in the properties it should be ok.如果在属性中添加带有dynamic: true breadcrumb字段应该没问题。

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

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

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