source-field.asciidoc 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. * On the fly <<highlighting,highlighting>>.
  37. * The ability to reindex from one Elasticsearch index to another, either
  38. to change mappings or analysis, or to upgrade an index to a new major
  39. version.
  40. * The ability to debug queries or aggregations by viewing the original
  41. document used at index time.
  42. * Potentially in the future, the ability to repair index corruption
  43. automatically.
  44. ==================================================
  45. TIP: If disk space is a concern, rather increase the
  46. <<index-codec,compression level>> instead of disabling the `_source`.
  47. [[include-exclude]]
  48. ==== Including / Excluding fields from `_source`
  49. An expert-only feature is the ability to prune the contents of the `_source`
  50. field after the document has been indexed, but before the `_source` field is
  51. stored.
  52. WARNING: Removing fields from the `_source` has similar downsides to disabling
  53. `_source`, especially the fact that you cannot reindex documents from one
  54. Elasticsearch index to another. Consider using
  55. <<source-filtering,source filtering>> instead.
  56. The `includes`/`excludes` parameters (which also accept wildcards) can be used
  57. as follows:
  58. [source,console]
  59. --------------------------------------------------
  60. PUT logs
  61. {
  62. "mappings": {
  63. "_source": {
  64. "includes": [
  65. "*.count",
  66. "meta.*"
  67. ],
  68. "excludes": [
  69. "meta.description",
  70. "meta.other.*"
  71. ]
  72. }
  73. }
  74. }
  75. PUT logs/_doc/1
  76. {
  77. "requests": {
  78. "count": 10,
  79. "foo": "bar" <1>
  80. },
  81. "meta": {
  82. "name": "Some metric",
  83. "description": "Some metric description", <1>
  84. "other": {
  85. "foo": "one", <1>
  86. "baz": "two" <1>
  87. }
  88. }
  89. }
  90. GET logs/_search
  91. {
  92. "query": {
  93. "match": {
  94. "meta.other.foo": "one" <2>
  95. }
  96. }
  97. }
  98. --------------------------------------------------
  99. <1> These fields will be removed from the stored `_source` field.
  100. <2> We can still search on this field, even though it is not in the stored `_source`.