stored-fields.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. [[search-request-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. For backwards compatibility, if the fields parameter specifies fields which are not stored (`store` mapping set to
  35. `false`), it will load the `_source` and extract it from it. This functionality has been replaced by the
  36. <<search-request-source-filtering,source filtering>> parameter.
  37. Field values fetched from the document it self are always returned as an array. Metadata fields like `_routing` and
  38. `_parent` fields are never returned as an array.
  39. Also only leaf fields can be returned via the `field` option. So object fields can't be returned and such requests
  40. will fail.
  41. Script fields can also be automatically detected and used as fields, so
  42. things like `_source.obj1.field1` can be used, though not recommended, as
  43. `obj1.field1` will work as well.
  44. ==== Disable stored fields entirely
  45. To disable the stored fields (and metadata fields) entirely use: `\_none_`:
  46. [source,js]
  47. --------------------------------------------------
  48. GET /_search
  49. {
  50. "stored_fields": "_none_",
  51. "query" : {
  52. "term" : { "user" : "kimchy" }
  53. }
  54. }
  55. --------------------------------------------------
  56. // CONSOLE
  57. NOTE: <<search-request-source-filtering,`_source`>> and <<search-request-version, `version`>> parameters cannot be activated if `_none_` is used.