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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With