enabled.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. "session": {
  19. "properties": {
  20. "user_id": {
  21. "type": "string",
  22. "index": "not_analyzed"
  23. },
  24. "last_updated": {
  25. "type": "date"
  26. },
  27. "session_data": { <1>
  28. "enabled": false
  29. }
  30. }
  31. }
  32. }
  33. }
  34. PUT my_index/session/session_1
  35. {
  36. "user_id": "kimchy",
  37. "session_data": { <2>
  38. "arbitrary_object": {
  39. "some_array": [ "foo", "bar", { "baz": 2 } ]
  40. }
  41. },
  42. "last_updated": "2015-12-06T18:20:22"
  43. }
  44. PUT my_index/session/session_2
  45. {
  46. "user_id": "jpountz",
  47. "session_data": "none", <3>
  48. "last_updated": "2015-12-06T18:22:13"
  49. }
  50. --------------------------------------------------
  51. // AUTOSENSE
  52. <1> The `session_data` field is disabled.
  53. <2> Any arbitrary data can be passed to the `session_data` field as it will be entirely ignored.
  54. <3> The `session_data` will also ignore values that are not JSON objects.
  55. The entire mapping type may be disabled as well, in which case the document is
  56. stored in the <<mapping-source-field,`_source`>> field, which means it can be
  57. retrieved, but none of its contents are indexed in any way:
  58. [source,js]
  59. --------------------------------------------------
  60. PUT my_index
  61. {
  62. "mappings": {
  63. "session": { <1>
  64. "enabled": false
  65. }
  66. }
  67. }
  68. PUT my_index/session/session_1
  69. {
  70. "user_id": "kimchy",
  71. "session_data": {
  72. "arbitrary_object": {
  73. "some_array": [ "foo", "bar", { "baz": 2 } ]
  74. }
  75. },
  76. "last_updated": "2015-12-06T18:20:22"
  77. }
  78. GET my_index/session/session_1 <2>
  79. GET my_index/_mapping <3>
  80. --------------------------------------------------
  81. // AUTOSENSE
  82. <1> The entire `session` mapping type is disabled.
  83. <2> The document can be retrieved.
  84. <3> Checking the mapping reveals that no fields have been added.
  85. TIP: The `enabled` setting is allowed to have different settings for fields of
  86. the same name in the same index. Its value can be updated on existing fields
  87. using the <<indices-put-mapping,PUT mapping API>>.