stored-fields.asciidoc 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. [[request-body-search-stored-fields]]
  2. ==== Stored Fields
  3. WARNING: The `stored_fields` parameter is about fields that are explicitly marked as
  4. stored in the mapping, which is off by default and generally not recommended.
  5. Use <<request-body-search-source-filtering,source filtering>> instead to select
  6. subsets of the original source document to be returned.
  7. Allows to selectively load specific stored fields for each document represented
  8. by a search hit.
  9. [source,console]
  10. --------------------------------------------------
  11. GET /_search
  12. {
  13. "stored_fields" : ["user", "postDate"],
  14. "query" : {
  15. "term" : { "user" : "kimchy" }
  16. }
  17. }
  18. --------------------------------------------------
  19. `*` can be used to load all stored fields from the document.
  20. An empty array will cause only the `_id` and `_type` for each hit to be
  21. returned, for example:
  22. [source,console]
  23. --------------------------------------------------
  24. GET /_search
  25. {
  26. "stored_fields" : [],
  27. "query" : {
  28. "term" : { "user" : "kimchy" }
  29. }
  30. }
  31. --------------------------------------------------
  32. If the requested fields are not stored (`store` mapping set to `false`), they will be ignored.
  33. Stored field values fetched from the document itself are always returned as an array. On the contrary, metadata fields like `_routing` are never returned as an array.
  34. Also only leaf fields can be returned via the `stored_fields` option. If an object field is specified, it will be ignored.
  35. NOTE: On its own, `stored_fields` cannot be used to load fields in nested
  36. objects -- if a field contains a nested object in its path, then no data will
  37. be returned for that stored field. To access nested fields, `stored_fields`
  38. must be used within an <<request-body-search-inner-hits, `inner_hits`>> block.
  39. ===== Disable stored fields entirely
  40. To disable the stored fields (and metadata fields) entirely use: `_none_`:
  41. [source,console]
  42. --------------------------------------------------
  43. GET /_search
  44. {
  45. "stored_fields": "_none_",
  46. "query" : {
  47. "term" : { "user" : "kimchy" }
  48. }
  49. }
  50. --------------------------------------------------
  51. NOTE: <<request-body-search-source-filtering,`_source`>> and <<request-body-search-version, `version`>> parameters cannot be activated if `_none_` is used.