count.asciidoc 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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.QueryBuilders.*;
  10. CountResponse response = client.prepareCount("test")
  11. .setQuery(termQuery("_type", "type1"))
  12. .execute()
  13. .actionGet();
  14. --------------------------------------------------
  15. For more information on the count operation, check out the REST
  16. {ref}/search-count.html[count] docs.
  17. === Operation Threading
  18. The count API allows one to set the threading model the operation will be
  19. performed when the actual execution of the API is performed on the same
  20. node (the API is executed on a shard that is allocated on the same
  21. server).
  22. There are three threading modes.The `NO_THREADS` mode means that the
  23. count operation will be executed on the calling thread. The
  24. `SINGLE_THREAD` mode means that the count operation will be executed on
  25. a single different thread for all local shards. The `THREAD_PER_SHARD`
  26. mode means that the count operation will be executed on a different
  27. thread for each local shard.
  28. The default mode is `SINGLE_THREAD`.