首页 > 解决方案 > Elasticsearch 为多个索引中的所有字段设置 `ignore_above`

问题描述

200+我有一个带索引的弹性搜索。文档有时包含无用的长文本字段,并且会占用过多的索引能力。

我想ignore_above自动为所有索引中的所有字段设置限制。我正在尝试为此使用索引模板

我找到了如何按名称为特定字段设置它的示例。
如何将它应用于所有(当前和未来)索引和字段?

标签: elasticsearchindexingmapping

解决方案


如何将它应用于所有(当前和未来)索引和字段?

模板中的设置仅适用于新索引。对于现有索引,您需要更新mappings各个索引的 。

在所有索引中应用此设置的方式因不同的 Elasticsearch 版本而异。我可以向您展示我尝试过的两个版本,并且知道它有效。

ES 2.4

    "mappings": {
    "_default_": {
        "dynamic_templates": [
            {
                "string_fields": {
                    "mapping": {
                        "ignore_above": 10922,
                        "index": "not_analyzed",
                        "type": "string"
                    },
                    "match_mapping_type": "string",
                    "match": "*"
                }
            }
        ]
        },
        "<your object type>": {
    <other settings>
    }
}

ES 6.1

"mappings": {
    "_default_" : {
        "dynamic_templates" : [
            {
                "string_fields" : {
                    "mapping" : {
                        "type" : "keyword",
                        "ignore_above" : 8191,
                        "index": true
                },
                "match_mapping_type" : "string",
                "match" : "*"
                }
            }
        ]
    }, 
    "<your object type>": {
    <other settings>
    }
}

mappingsunder_default_将适用于所有对象类型,并且可以使用设置 under 覆盖<your object type>

高温高压


推荐阅读