stored-fields.asciidoc 2.1 KB

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