fields.asciidoc 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. [[search-request-fields]]
  2. === Fields
  3. Allows to selectively load specific stored fields for each document represented
  4. by a search hit.
  5. [source,js]
  6. --------------------------------------------------
  7. {
  8. "fields" : ["user", "postDate"],
  9. "query" : {
  10. "term" : { "user" : "kimchy" }
  11. }
  12. }
  13. --------------------------------------------------
  14. `*` can be used to load all stored fields from the document.
  15. An empty array will cause only the `_id` and `_type` for each hit to be
  16. returned, for example:
  17. [source,js]
  18. --------------------------------------------------
  19. {
  20. "fields" : [],
  21. "query" : {
  22. "term" : { "user" : "kimchy" }
  23. }
  24. }
  25. --------------------------------------------------
  26. For backwards compatibility, if the fields parameter specifies fields which are not stored (`store` mapping set to
  27. `false`), it will load the `_source` and extract it from it. This functionality has been replaced by the
  28. <<search-request-source-filtering,source filtering>> parameter.
  29. Script fields can also be automatically detected and used as fields, so
  30. things like `_source.obj1.obj2` can be used, though not recommended, as
  31. `obj1.obj2` will work as well.
  32. [[partial]]
  33. ==== Partial
  34. deprecated[1.0.0Beta1,Replaced by <<search-request-source-filtering>>]
  35. When loading data from `_source`, partial fields can be used to use
  36. wildcards to control what part of the `_source` will be loaded based on
  37. `include` and `exclude` patterns. For example:
  38. [source,js]
  39. --------------------------------------------------
  40. {
  41. "query" : {
  42. "match_all" : {}
  43. },
  44. "partial_fields" : {
  45. "partial1" : {
  46. "include" : "obj1.obj2.*",
  47. }
  48. }
  49. }
  50. --------------------------------------------------
  51. And one that will also exclude `obj1.obj3`:
  52. [source,js]
  53. --------------------------------------------------
  54. {
  55. "query" : {
  56. "match_all" : {}
  57. },
  58. "partial_fields" : {
  59. "partial1" : {
  60. "include" : "obj1.obj2.*",
  61. "exclude" : "obj1.obj3.*"
  62. }
  63. }
  64. }
  65. --------------------------------------------------
  66. Both `include` and `exclude` support multiple patterns:
  67. [source,js]
  68. --------------------------------------------------
  69. {
  70. "query" : {
  71. "match_all" : {}
  72. },
  73. "partial_fields" : {
  74. "partial1" : {
  75. "include" : ["obj1.obj2.*", "obj1.obj4.*"],
  76. "exclude" : "obj1.obj3.*"
  77. }
  78. }
  79. }
  80. --------------------------------------------------