source-field.asciidoc 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. [[mapping-source-field]]
  2. === `_source` field
  3. The `_source` field contains the original JSON document body that was passed
  4. at index time. The `_source` field itself is not indexed (and thus is not
  5. searchable), but it is stored so that it can be returned when executing
  6. _fetch_ requests, like <<docs-get,get>> or <<search-search,search>>.
  7. If disk usage is important to you then have a look at
  8. <<synthetic-source,synthetic `_source`>> which shrinks disk usage at the cost of
  9. only supporting a subset of mappings and slower fetches or (not recommended)
  10. <<disable-source-field,disabling the `_source` field>> which also shrinks disk
  11. usage but disables many features.
  12. include::synthetic-source.asciidoc[]
  13. [[disable-source-field]]
  14. ==== Disabling the `_source` field
  15. Though very handy to have around, the source field does incur storage overhead
  16. within the index. For this reason, it can be disabled as follows:
  17. [source,console]
  18. --------------------------------------------------
  19. PUT my-index-000001
  20. {
  21. "mappings": {
  22. "_source": {
  23. "enabled": false
  24. }
  25. }
  26. }
  27. --------------------------------------------------
  28. [WARNING]
  29. .Think before disabling the `_source` field
  30. ==================================================
  31. Users often disable the `_source` field without thinking about the
  32. consequences, and then live to regret it. If the `_source` field isn't
  33. available then a number of features are not supported:
  34. * The <<docs-update,`update`>>, <<docs-update-by-query,`update_by_query`>>,
  35. and <<docs-reindex,`reindex`>> APIs.
  36. * In the {kib} link:{kibana-ref}/discover.html[Discover] application, field data will not be displayed.
  37. * On the fly <<highlighting,highlighting>>.
  38. * The ability to reindex from one Elasticsearch index to another, either
  39. to change mappings or analysis, or to upgrade an index to a new major
  40. version.
  41. * The ability to debug queries or aggregations by viewing the original
  42. document used at index time.
  43. * Potentially in the future, the ability to repair index corruption
  44. automatically.
  45. ==================================================
  46. TIP: If disk space is a concern, rather increase the
  47. <<index-codec,compression level>> instead of disabling the `_source`.
  48. [[include-exclude]]
  49. ==== Including / Excluding fields from `_source`
  50. An expert-only feature is the ability to prune the contents of the `_source`
  51. field after the document has been indexed, but before the `_source` field is
  52. stored.
  53. WARNING: Removing fields from the `_source` has similar downsides to disabling
  54. `_source`, especially the fact that you cannot reindex documents from one
  55. Elasticsearch index to another. Consider using
  56. <<source-filtering,source filtering>> instead.
  57. The `includes`/`excludes` parameters (which also accept wildcards) can be used
  58. as follows:
  59. [source,console]
  60. --------------------------------------------------
  61. PUT logs
  62. {
  63. "mappings": {
  64. "_source": {
  65. "includes": [
  66. "*.count",
  67. "meta.*"
  68. ],
  69. "excludes": [
  70. "meta.description",
  71. "meta.other.*"
  72. ]
  73. }
  74. }
  75. }
  76. PUT logs/_doc/1
  77. {
  78. "requests": {
  79. "count": 10,
  80. "foo": "bar" <1>
  81. },
  82. "meta": {
  83. "name": "Some metric",
  84. "description": "Some metric description", <1>
  85. "other": {
  86. "foo": "one", <1>
  87. "baz": "two" <1>
  88. }
  89. }
  90. }
  91. GET logs/_search
  92. {
  93. "query": {
  94. "match": {
  95. "meta.other.foo": "one" <2>
  96. }
  97. }
  98. }
  99. --------------------------------------------------
  100. <1> These fields will be removed from the stored `_source` field.
  101. <2> We can still search on this field, even though it is not in the stored `_source`.