Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling field analyzing by default in elastic search

Tags:

Is it possible to enable indexing of elastic search fields selectively for a type?

Through the mapping settings for a specific index, one can set the property

{ "index" : "not_analyzed" }

For a specific field. Since my document has too many fields and is likely to change structure in the future, I would need a mapping where fields are not analyzed by default unless specified differently.

Is this possible?

like image 328
Edmondo1984 Avatar asked Dec 19 '14 16:12

Edmondo1984


1 Answers

Yes - have a look at dynamic templates

Try the following:

PUT /my_index {   "mappings": {     "my_type": {         "dynamic_templates": [             { "notanalyzed": {                   "match":              "*",                    "match_mapping_type": "string",                   "mapping": {                       "type":        "string",                       "index":       "not_analyzed"                   }                }             }           ]        }    } } 

The dynamic template is for new fields that aren't covered by your mapping - from the docs:

With dynamic_templates, you can take complete control over the mapping that is generated for newly detected fields.

You can also vary the mapping according to the field name, e.g. use "match": "*_data", to have a different set of mappings for field names ending in "_data".

like image 174
Olly Cruickshank Avatar answered Sep 27 '22 20:09

Olly Cruickshank