| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 | [[enabled]]=== `enabled`Elasticsearch tries to index all of the fields you give it, but sometimes youwant to just store the field without indexing it.  For instance, imagine thatyou are using Elasticsearch as a web session store.  You may want to index thesession ID and last update time, but you don't need to query or runaggregations on the session data itself.The `enabled` setting, which can be applied only to the top-level mappingdefinition and to <<object,`object`>> fields, causes Elasticsearch to skipparsing of the contents of the field entirely.  The JSON can still be retrievedfrom the <<mapping-source-field,`_source`>> field, but it is not searchable orstored in any other way:[source,console]--------------------------------------------------PUT my_index{  "mappings": {    "properties": {      "user_id": {        "type":  "keyword"      },      "last_updated": {        "type": "date"      },      "session_data": { <1>        "type": "object",        "enabled": false      }    }  }}PUT my_index/_doc/session_1{  "user_id": "kimchy",  "session_data": { <2>    "arbitrary_object": {      "some_array": [ "foo", "bar", { "baz": 2 } ]    }  },  "last_updated": "2015-12-06T18:20:22"}PUT my_index/_doc/session_2{  "user_id": "jpountz",  "session_data": "none", <3>  "last_updated": "2015-12-06T18:22:13"}--------------------------------------------------<1> The `session_data` field is disabled.<2> Any arbitrary data can be passed to the `session_data` field as it will be entirely ignored.<3> The `session_data` will also ignore values that are not JSON objects.The entire mapping may be disabled as well, in which case the document isstored in the <<mapping-source-field,`_source`>> field, which means it can beretrieved, but none of its contents are indexed in any way:[source,console]--------------------------------------------------PUT my_index{  "mappings": {    "enabled": false <1>  }}PUT my_index/_doc/session_1{  "user_id": "kimchy",  "session_data": {    "arbitrary_object": {      "some_array": [ "foo", "bar", { "baz": 2 } ]    }  },  "last_updated": "2015-12-06T18:20:22"}GET my_index/_doc/session_1 <2>GET my_index/_mapping <3>--------------------------------------------------<1> The entire mapping is disabled.<2> The document can be retrieved.<3> Checking the mapping reveals that no fields have been added.The `enabled` setting for existing fields and the top-level mappingdefinition cannot be updated.Note that because Elasticsearch completely skips parsing the fieldcontents, it is possible to add non-object data to a disabled field:[source,console]--------------------------------------------------PUT my_index{  "mappings": {    "properties": {      "session_data": {        "type": "object",        "enabled": false      }    }  }}PUT my_index/_doc/session_1{  "session_data": "foo bar" <1>}--------------------------------------------------<1> The document is added successfully, even though `session_data` contains non-object data.
 |