exists-query.asciidoc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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,js]
  15. ----
  16. GET /_search
  17. {
  18. "query": {
  19. "exists": {
  20. "field": "user"
  21. }
  22. }
  23. }
  24. ----
  25. // CONSOLE
  26. [[exists-query-top-level-params]]
  27. ==== Top-level parameters for `exists`
  28. `field`::
  29. Name of the field you wish to search.
  30. +
  31. While a field is deemed non-existant if the JSON value is `null` or `[]`, these 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,js]
  46. ----
  47. GET /_search
  48. {
  49. "query": {
  50. "bool": {
  51. "must_not": {
  52. "exists": {
  53. "field": "user"
  54. }
  55. }
  56. }
  57. }
  58. }
  59. ----
  60. // CONSOLE