stored-fields.asciidoc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [[search-request-stored-fields]]
  2. === 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 <<search-request-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,js]
  10. --------------------------------------------------
  11. GET /_search
  12. {
  13. "stored_fields" : ["user", "postDate"],
  14. "query" : {
  15. "term" : { "user" : "kimchy" }
  16. }
  17. }
  18. --------------------------------------------------
  19. // CONSOLE
  20. `*` can be used to load all stored fields from the document.
  21. An empty array will cause only the `_id` and `_type` for each hit to be
  22. returned, for example:
  23. [source,js]
  24. --------------------------------------------------
  25. GET /_search
  26. {
  27. "stored_fields" : [],
  28. "query" : {
  29. "term" : { "user" : "kimchy" }
  30. }
  31. }
  32. --------------------------------------------------
  33. // CONSOLE
  34. If the requested fields are not stored (`store` mapping set to `false`), they will be ignored.
  35. 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.
  36. Also only leaf fields can be returned via the `field` option. So object fields can't be returned and such requests
  37. will fail.
  38. Script fields can also be automatically detected and used as fields, so
  39. things like `_source.obj1.field1` can be used, though not recommended, as
  40. `obj1.field1` will work as well.
  41. ==== Disable stored fields entirely
  42. To disable the stored fields (and metadata fields) entirely use: `_none_`:
  43. [source,js]
  44. --------------------------------------------------
  45. GET /_search
  46. {
  47. "stored_fields": "_none_",
  48. "query" : {
  49. "term" : { "user" : "kimchy" }
  50. }
  51. }
  52. --------------------------------------------------
  53. // CONSOLE
  54. NOTE: <<search-request-source-filtering,`_source`>> and <<search-request-version, `version`>> parameters cannot be activated if `_none_` is used.