Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify which fields are indexed in ElasticSearch

Tags:

I have a document with a number of fields that I never query on so I would like to turn indexing on those fields off to save resources. I believe I need to disable the _all field, but how do I specify which fields are indexed then?

like image 958
Michael Avatar asked Nov 29 '12 13:11

Michael


People also ask

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.

How does Elasticsearch define index?

An index is defined as: An index is like a 'database' in a relational database. It has a mapping which defines multiple types. An index is a logical namespace which maps to one or more primary shards and can have zero or more replica shards.

What indexed fields?

A field that is incorporated into the index at index time. Indexed fields include the default fields, such as host, source, and sourcetype, as well as custom index-time field extractions. In rare cases, there is some value to adding fields to the index.


1 Answers

By default all the fields are indexed within the _all special field as well, which provides the so called catchall feature out of the box. However, you can specify for each field in your mapping whether you want to add it to the _all field or not, through the include_in_all option:

"person" : {     "properties" : {         "name" : {             "type" : "string", "store" : "yes", "include_in_all" : false         }     } } 

The above example disables the default behaviour for the name field, which won't be part of the _all field.

Otherwise, if you don't need the _all field at all for a specific type you can disable it like this, again in your mapping:

"person" : {     "_all" : {"enabled" : false},     "properties" : {         "name" : {             "type" : "string", "store" : "yes"         }     } } 

When you disable it your fields will still be indexed separately, but you won't have the catchall feature that _all provides. You will need then to query your specific fields instead of relying on the _all special field, that's it. In fact, when you query and don't specify a field, elasticsearch queries the _all field under the hood, unless you override the default field to query.

like image 190
javanna Avatar answered Oct 06 '22 01:10

javanna