2015-08-06 11:24:29 -04:00
|
|
|
[[enabled]]
|
|
|
|
=== `enabled`
|
|
|
|
|
|
|
|
Elasticsearch tries to index all of the fields you give it, but sometimes you
|
|
|
|
want to just store the field without indexing it. For instance, imagine that
|
|
|
|
you are using Elasticsearch as a web session store. You may want to index the
|
|
|
|
session ID and last update time, but you don't need to query or run
|
|
|
|
aggregations on the session data itself.
|
|
|
|
|
2019-04-09 13:49:01 -04:00
|
|
|
The `enabled` setting, which can be applied only to the top-level mapping
|
|
|
|
definition and to <<object,`object`>> fields, causes Elasticsearch to skip
|
|
|
|
parsing of the contents of the field entirely. The JSON can still be retrieved
|
|
|
|
from the <<mapping-source-field,`_source`>> field, but it is not searchable or
|
|
|
|
stored in any other way:
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"user_id": {
|
|
|
|
"type": "keyword"
|
|
|
|
},
|
|
|
|
"last_updated": {
|
|
|
|
"type": "date"
|
|
|
|
},
|
|
|
|
"session_data": { <1>
|
2019-04-09 13:49:01 -04:00
|
|
|
"type": "object",
|
2019-01-22 09:13:52 -05:00
|
|
|
"enabled": false
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/session_1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"user_id": "kimchy",
|
|
|
|
"session_data": { <2>
|
|
|
|
"arbitrary_object": {
|
|
|
|
"some_array": [ "foo", "bar", { "baz": 2 } ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"last_updated": "2015-12-06T18:20:22"
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/session_2
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"user_id": "jpountz",
|
|
|
|
"session_data": "none", <3>
|
|
|
|
"last_updated": "2015-12-06T18:22:13"
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
<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.
|
|
|
|
|
2019-04-09 13:49:01 -04:00
|
|
|
The entire mapping may be disabled as well, in which case the document is
|
2015-08-06 11:24:29 -04:00
|
|
|
stored in the <<mapping-source-field,`_source`>> field, which means it can be
|
|
|
|
retrieved, but none of its contents are indexed in any way:
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2019-01-22 09:13:52 -05:00
|
|
|
PUT my_index
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"enabled": false <1>
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
PUT my_index/_doc/session_1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"user_id": "kimchy",
|
|
|
|
"session_data": {
|
|
|
|
"arbitrary_object": {
|
|
|
|
"some_array": [ "foo", "bar", { "baz": 2 } ]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"last_updated": "2015-12-06T18:20:22"
|
|
|
|
}
|
|
|
|
|
2017-12-14 11:47:53 -05:00
|
|
|
GET my_index/_doc/session_1 <2>
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
GET my_index/_mapping <3>
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2019-04-09 13:49:01 -04:00
|
|
|
<1> The entire mapping is disabled.
|
2015-08-06 11:24:29 -04:00
|
|
|
<2> The document can be retrieved.
|
|
|
|
<3> Checking the mapping reveals that no fields have been added.
|
2015-08-12 15:21:37 -04:00
|
|
|
|
2019-06-28 06:58:22 -04:00
|
|
|
The `enabled` setting for existing fields and the top-level mapping
|
|
|
|
definition cannot be updated.
|
2015-08-12 15:21:37 -04:00
|
|
|
|
2019-04-09 13:49:01 -04:00
|
|
|
Note that because Elasticsearch completely skips parsing the field
|
|
|
|
contents, it is possible to add non-object data to a disabled field:
|
2019-09-06 11:31:13 -04:00
|
|
|
|
|
|
|
[source,console]
|
2019-04-09 13:49:01 -04:00
|
|
|
--------------------------------------------------
|
|
|
|
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.
|