count.asciidoc 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. [[count]]
  2. == Count API
  3. The count API allows one to easily execute a query and get the number of
  4. matches for that query. It can be executed across one or more indices
  5. and across one or more types. The query can be provided using the
  6. {ref}/query-dsl.html[Query DSL].
  7. [source,java]
  8. --------------------------------------------------
  9. import static org.elasticsearch.index.query.xcontent.FilterBuilders.*;
  10. import static org.elasticsearch.index.query.xcontent.QueryBuilders.*;
  11. CountResponse response = client.prepareCount("test")
  12. .setQuery(termQuery("_type", "type1"))
  13. .execute()
  14. .actionGet();
  15. --------------------------------------------------
  16. For more information on the count operation, check out the REST
  17. {ref}/search-count.html[count] docs.
  18. === Operation Threading
  19. The count API allows one to set the threading model the operation will be
  20. performed when the actual execution of the API is performed on the same
  21. node (the API is executed on a shard that is allocated on the same
  22. server).
  23. There are three threading modes.The `NO_THREADS` mode means that the
  24. count operation will be executed on the calling thread. The
  25. `SINGLE_THREAD` mode means that the count operation will be executed on
  26. a single different thread for all local shards. The `THREAD_PER_SHARD`
  27. mode means that the count operation will be executed on a different
  28. thread for each local shard.
  29. The default mode is `SINGLE_THREAD`.