How to count records using JAVA client api?


I am using following code to get count of records indexed which satisfy the given criteria, but this is not working and giving me all the records indexed in the type. How do I get count of records satisfying the criteria.

SearchRequestBuilder searchRequest = client.prepareSearch(indexName);
SearchResponse response = searchRequest.setSource(new SearchSourceBuilder().size(10000).query(QueryBuilders.queryStringQuery(queryString).get();

return response.getHits().getHits().length;

The above code is not working in Elasticsearch 5 Java client api, please help.

Something like that should work:

return client().prepareSearch(indexName)

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.