exists.asciidoc 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. [[search-exists]]
  2. == Search Exists API
  3. The exists API allows to easily determine if any
  4. matching documents exist for a provided query. It can be executed across one or more indices
  5. and across one or more types. The query can either be provided using a
  6. simple query string as a parameter, or using the
  7. <<query-dsl,Query DSL>> defined within the request
  8. body. Here is an example:
  9. [source,js]
  10. --------------------------------------------------
  11. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search/exists?q=user:kimchy'
  12. $ curl -XGET 'http://localhost:9200/twitter/tweet/_search/exists' -d '
  13. {
  14. "query" : {
  15. "term" : { "user" : "kimchy" }
  16. }
  17. }'
  18. --------------------------------------------------
  19. NOTE: The query being sent in the body must be nested in a `query` key, same as
  20. how the <<search-search,search api>> works.
  21. Both the examples above do the same thing, which is determine the existence of
  22. tweets from the twitter index for a certain user. The response body will be of
  23. the following format:
  24. [source,js]
  25. --------------------------------------------------
  26. {
  27. "exists" : true
  28. }
  29. --------------------------------------------------
  30. [float]
  31. === Multi index, Multi type
  32. The exists API can be applied to <<search-multi-index-type,multiple types in multiple indices>>.
  33. [float]
  34. === Request Parameters
  35. When executing exists using the query parameter `q`, the query passed is
  36. a query string using Lucene query parser. There are additional
  37. parameters that can be passed:
  38. [cols="<,<",options="header",]
  39. |=======================================================================
  40. |Name |Description
  41. |`df` |The default field to use when no field prefix is defined within the
  42. query.
  43. |`analyzer` |The analyzer name to be used when analyzing the query string.
  44. |`default_operator` |The default operator to be used, can be `AND` or
  45. `OR`. Defaults to `OR`.
  46. |`lenient` |If set to true will cause format based failures (like
  47. providing text to a numeric field) to be ignored. Defaults to false.
  48. |`lowercase_expanded_terms` |Should terms be automatically lowercased or
  49. not. Defaults to `true`.
  50. |`analyze_wildcard` |Should wildcard and prefix queries be analyzed or
  51. not. Defaults to `false`.
  52. |=======================================================================
  53. [float]
  54. === Request Body
  55. The exists API can use the <<query-dsl,Query DSL>> within
  56. its body in order to express the query that should be executed. The body
  57. content can also be passed as a REST parameter named `source`.
  58. HTTP GET and HTTP POST can be used to execute exists with body.
  59. Since not all clients support GET with body, POST is allowed as well.
  60. [float]
  61. === Distributed
  62. The exists operation is broadcast across all shards. For each shard id
  63. group, a replica is chosen and executed against it. This means that
  64. replicas increase the scalability of exists. The exists operation also
  65. early terminates shard requests once the first shard reports matched
  66. document existence.
  67. [float]
  68. === Routing
  69. The routing value (a comma separated list of the routing values) can be
  70. specified to control which shards the exists request will be executed on.