Viacheslav Shalamov
Viacheslav Shalamov

Reputation: 4417

Elasticsearch set `ignore_above` for all fields in multiple indices

I have an elastic-search with 200+ indices. Documents sometimes contain long text fields which are useless and take too much indexing power.

I want need to set limit with ignore_above for all fields in all indices automatically. I'm trying to use index templates for that.

I've found examples how to set it up for specific fields by name.
How can I apply it for all (current and future) indices and fields?

Upvotes: 1

Views: 505

Answers (1)

avp
avp

Reputation: 3340

How can I apply it for all (current and future) indices and fields?

The settings in the template will only be applicable to the new indices. For existing indices, you need to update the mappings for individual indices.

The way to apply this setting across all indices varies between different Elasticsearch versions. I can show you for two of the versions I have tried and know it works.

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>
    }
}

mappings under _default_ will be applicable to all the object types and can be overridden using setting under <your object type>.

HTH

Upvotes: 1

Related Questions