exists-query.asciidoc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. [[query-dsl-exists-query]]
  2. === Exists query
  3. ++++
  4. <titleabbrev>Exists</titleabbrev>
  5. ++++
  6. Returns documents that contain an indexed value for a field.
  7. An indexed value may not exist for a document's field due to a variety of reasons:
  8. * The field in the source JSON is `null` or `[]`
  9. * The field has `"index" : false` set in the mapping
  10. * The length of the field value exceeded an `ignore_above` setting in the mapping
  11. * The field value was malformed and `ignore_malformed` was defined in the mapping
  12. [[exists-query-ex-request]]
  13. ==== Example request
  14. [source,console]
  15. ----
  16. GET /_search
  17. {
  18. "query": {
  19. "exists": {
  20. "field": "user"
  21. }
  22. }
  23. }
  24. ----
  25. [[exists-query-top-level-params]]
  26. ==== Top-level parameters for `exists`
  27. `field`::
  28. (Required, string) Name of the field you wish to search.
  29. +
  30. While a field is deemed non-existant if the JSON value is `null` or `[]`, these
  31. values will indicate the field does exist:
  32. +
  33. * Empty strings, such as `""` or `"-"`
  34. * Arrays containing `null` and another value, such as `[null, "foo"]`
  35. * A custom <<null-value, `null-value`>>, defined in field mapping
  36. [[exists-query-notes]]
  37. ==== Notes
  38. [[find-docs-null-values]]
  39. ===== Find documents missing indexed values
  40. To find documents that are missing an indexed value for a field,
  41. use the `must_not` <<query-dsl-bool-query, boolean query>> with the `exists`
  42. query.
  43. The following search returns documents that are missing an indexed value for
  44. the `user` field.
  45. [source,console]
  46. ----
  47. GET /_search
  48. {
  49. "query": {
  50. "bool": {
  51. "must_not": {
  52. "exists": {
  53. "field": "user"
  54. }
  55. }
  56. }
  57. }
  58. }
  59. ----