exists-query.asciidoc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. [[query-dsl-exists-query]]
  2. === Exists Query
  3. Returns documents that contain a value other than `null` or `[]` in a provided
  4. field.
  5. [[exists-query-ex-request]]
  6. ==== Example request
  7. [source,js]
  8. ----
  9. GET /_search
  10. {
  11. "query": {
  12. "exists": {
  13. "field": "user"
  14. }
  15. }
  16. }
  17. ----
  18. // CONSOLE
  19. [[exists-query-top-level-params]]
  20. ==== Top-level parameters for `exists`
  21. `field`::
  22. Name of the field you wish to search.
  23. +
  24. To return a document, this field must exist and contain a value other
  25. than `null` or `[]`. These values can include:
  26. +
  27. * Empty strings, such as `""` or `"-"`
  28. * Arrays containing `null` and another value, such as `[null, "foo"]`
  29. * A custom <<null-value, `null-value`>>, defined in field mapping
  30. [[exists-query-notes]]
  31. ==== Notes
  32. [[find-docs-null-values]]
  33. ===== Find documents with null values
  34. To find documents that contain only `null` values or `[]` in a provided field,
  35. use the `must_not` <<query-dsl-bool-query, boolean query>> with the `exists`
  36. query.
  37. The following search returns documents that contain only `null` values or `[]`
  38. in the `user` field.
  39. [source,js]
  40. ----
  41. GET /_search
  42. {
  43. "query": {
  44. "bool": {
  45. "must_not": {
  46. "exists": {
  47. "field": "user"
  48. }
  49. }
  50. }
  51. }
  52. }
  53. ----
  54. // CONSOLE