enabled.asciidoc 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. [[enabled]]
  2. === `enabled`
  3. Elasticsearch tries to index all of the fields you give it, but sometimes you
  4. want to just store the field without indexing it. For instance, imagine that
  5. you are using Elasticsearch as a web session store. You may want to index the
  6. session ID and last update time, but you don't need to query or run
  7. aggregations on the session data itself.
  8. The `enabled` setting, which can be applied only to the mapping type and to
  9. <<object,`object`>> fields, causes Elasticsearch to skip parsing of the
  10. contents of the field entirely. The JSON can still be retrieved from the
  11. <<mapping-source-field,`_source`>> field, but it is not searchable or stored
  12. in any other way:
  13. [source,js]
  14. --------------------------------------------------
  15. PUT my_index
  16. {
  17. "mappings": {
  18. "properties": {
  19. "user_id": {
  20. "type": "keyword"
  21. },
  22. "last_updated": {
  23. "type": "date"
  24. },
  25. "session_data": { <1>
  26. "enabled": false
  27. }
  28. }
  29. }
  30. }
  31. PUT my_index/_doc/session_1
  32. {
  33. "user_id": "kimchy",
  34. "session_data": { <2>
  35. "arbitrary_object": {
  36. "some_array": [ "foo", "bar", { "baz": 2 } ]
  37. }
  38. },
  39. "last_updated": "2015-12-06T18:20:22"
  40. }
  41. PUT my_index/_doc/session_2
  42. {
  43. "user_id": "jpountz",
  44. "session_data": "none", <3>
  45. "last_updated": "2015-12-06T18:22:13"
  46. }
  47. --------------------------------------------------
  48. // CONSOLE
  49. <1> The `session_data` field is disabled.
  50. <2> Any arbitrary data can be passed to the `session_data` field as it will be entirely ignored.
  51. <3> The `session_data` will also ignore values that are not JSON objects.
  52. The entire mapping type may be disabled as well, in which case the document is
  53. stored in the <<mapping-source-field,`_source`>> field, which means it can be
  54. retrieved, but none of its contents are indexed in any way:
  55. [source,js]
  56. --------------------------------------------------
  57. PUT my_index
  58. {
  59. "mappings": {
  60. "enabled": false <1>
  61. }
  62. }
  63. PUT my_index/_doc/session_1
  64. {
  65. "user_id": "kimchy",
  66. "session_data": {
  67. "arbitrary_object": {
  68. "some_array": [ "foo", "bar", { "baz": 2 } ]
  69. }
  70. },
  71. "last_updated": "2015-12-06T18:20:22"
  72. }
  73. GET my_index/_doc/session_1 <2>
  74. GET my_index/_mapping <3>
  75. --------------------------------------------------
  76. // CONSOLE
  77. <1> The entire mapping type is disabled.
  78. <2> The document can be retrieved.
  79. <3> Checking the mapping reveals that no fields have been added.
  80. TIP: The `enabled` setting can be updated on existing fields
  81. using the <<indices-put-mapping,PUT mapping API>>.