Home > OS >  Is it possible to declare "text" and "keyword" on the same field in elasticsearc
Is it possible to declare "text" and "keyword" on the same field in elasticsearc

Time:10-20

I want to be able to both search on a field and aggregate it. Is there any option to declare a field both as text and keyword?

I've read a little bit about multifields. Is that a possible solution?

CodePudding user response:

By default, Elasticsearch will map text values to a text field, with a keyword sub-field. Your mapping would look like this:

 "mappings": {
        "properties": {
            "newfield": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    }

As a consequence, it will both be possible to perform full-text search on newfield and keyword search and aggregations using the newfield.keyword field.

Relevant documentation: Dynamic field mapping

  • Related