Count API

edit

The count API allows one to easily execute a query and get the number of matches for that query. It can be executed across one or more indices and across one or more types. The query can be provided using the Query DSL.

import static org.elasticsearch.index.query.xcontent.FilterBuilders.*;
import static org.elasticsearch.index.query.xcontent.QueryBuilders.*;

CountResponse response = client.prepareCount("test")
        .setQuery(termQuery("_type", "type1"))
        .execute()
        .actionGet();

For more information on the count operation, check out the REST count docs.