docvalue-fields.asciidoc 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. [[search-request-docvalue-fields]]
  2. === Doc value Fields
  3. Allows to return the <<doc-values,doc value>> representation of a field for each hit, for
  4. example:
  5. [source,js]
  6. --------------------------------------------------
  7. GET /_search
  8. {
  9. "query" : {
  10. "match_all": {}
  11. },
  12. "docvalue_fields" : [
  13. "my_ip_field", <1>
  14. {
  15. "field": "my_keyword_field" <2>
  16. },
  17. {
  18. "field": "my_date_field",
  19. "format": "epoch_millis" <3>
  20. }
  21. ]
  22. }
  23. --------------------------------------------------
  24. // CONSOLE
  25. <1> the name of the field
  26. <2> an object notation is supported as well
  27. <3> the object notation allows to specify a custom format
  28. Doc value fields can work on fields that have doc-values enabled, regardless of whether they are stored
  29. `*` can be used as a wild card, for example:
  30. [source,js]
  31. --------------------------------------------------
  32. GET /_search
  33. {
  34. "query" : {
  35. "match_all": {}
  36. },
  37. "docvalue_fields" : [
  38. {
  39. "field": "*_date_field", <1>
  40. "format": "epoch_millis" <2>
  41. }
  42. ]
  43. }
  44. --------------------------------------------------
  45. // CONSOLE
  46. <1> Match all fields ending with `field`
  47. <2> Format to be applied to all matching fields.
  48. Note that if the fields parameter specifies fields without docvalues it will try to load the value from the fielddata cache
  49. causing the terms for that field to be loaded to memory (cached), which will result in more memory consumption.
  50. [float]
  51. ==== Custom formats
  52. While most fields do not support custom formats, some of them do:
  53. - <<date,Date>> fields can take any <<mapping-date-format,date format>>.
  54. - <<number,Numeric>> fields accept a https://docs.oracle.com/javase/8/docs/api/java/text/DecimalFormat.html[DecimalFormat pattern].
  55. By default fields are formatted based on a sensible configuration that depends
  56. on their mappings: `long`, `double` and other numeric fields are formatted as
  57. numbers, `keyword` fields are formatted as strings, `date` fields are formatted
  58. with the configured `date` format, etc.
  59. NOTE: On its own, `docvalue_fields` cannot be used to load fields in nested
  60. objects -- if a field contains a nested object in its path, then no data will
  61. be returned for that docvalue field. To access nested fields, `docvalue_fields`
  62. must be used within an <<search-request-inner-hits, `inner_hits`>> block.