stored-fields.asciidoc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 `field` option. So object fields can't be returned and such requests
  35. will fail.
  36. Script fields can also be automatically detected and used as fields, so
  37. things like `_source.obj1.field1` can be used, though not recommended, as
  38. `obj1.field1` will work as well.
  39. NOTE: On its own, `stored_fields` cannot be used to load fields in nested
  40. objects -- if a field contains a nested object in its path, then no data will
  41. be returned for that stored field. To access nested fields, `stored_fields`
  42. must be used within an <<request-body-search-inner-hits, `inner_hits`>> block.
  43. ===== Disable stored fields entirely
  44. To disable the stored fields (and metadata fields) entirely use: `_none_`:
  45. [source,console]
  46. --------------------------------------------------
  47. GET /_search
  48. {
  49. "stored_fields": "_none_",
  50. "query" : {
  51. "term" : { "user" : "kimchy" }
  52. }
  53. }
  54. --------------------------------------------------
  55. NOTE: <<request-body-search-source-filtering,`_source`>> and <<request-body-search-version, `version`>> parameters cannot be activated if `_none_` is used.