exists-query.asciidoc 1.6 KB

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