Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch. Is it possible to set mapping for field in index for all types?

An Elasticsearch cluster can contain multiple Indices (databases), which in turn contain multiple Types (tables). Is it possible to set mapping for field in index for all types?

like image 815
Iana Mykhailenko Avatar asked Dec 03 '14 17:12

Iana Mykhailenko


People also ask

Can Elasticsearch index have multiple mappings?

No, if you want to use a single index, you would need to define a single mapping that combines the fields of each document type. A better way might be to define separate indices on the same cluster for each document type.

Can I change mapping for existing index Elasticsearch?

Changing the mapping of an existing field could invalidate any data that's already indexed. If you need to change the mapping of an existing field, create a new data stream and reindex your data into it. See Use reindex to change mappings or settings.

Can Elasticsearch index have multiple types?

From Elasticsearch version 6.0 by default index doesn't allow multiple types per index. The better option is to always have one document type per index. The single responsibility of the index is to maintain the single document type/mapping type per index.

Are all fields indexed in Elasticsearch?

By default, Elasticsearch indexes all data in every field and each indexed field has a dedicated, optimized data structure. For example, text fields are stored in inverted indices, and numeric and geo fields are stored in BKD trees.


1 Answers

Use the _default_ mapping setting on the Index. When the type is created it will have the field mapping your looking for.

PUT /my_index{
"mappings": {
    "_default_": {
            "properties": {
                "field1": {
                    "type": "string",
                    "index": "analyzed"
                }
             }
     }
}

You could also use an Index Template, if you wanted all new indexes to have this default setting. I think it would be a good enhancement to have a Dynamic Templates be available at Index Level so they can be applied across types. This doesn't appear possible now.

like image 163
Andy Avatar answered Sep 22 '22 22:09

Andy