How to get count of specific value in elasticsearch java clinet

I am using elasticsearch-java 8.12, and I want to get the count of specific value,
in my example I have log index, and there is a field called result, I want to get the number of documents that the result field is "correct", how to do that?
I made a search but the document does not contains an explanation for it

Something like this should work:

try {
    client.indices().delete(dir -> dir.index("search-data"));
} catch (ElasticsearchException ignored) { }
client.index(ir -> ir.index("search-data").id("1").withJson(new StringReader("{\"result\":\"correct\"}")));
client.indices().refresh(rr -> rr.index("search-data"));
SearchResponse<Void> response = client.search(sr -> sr
                .index("search-data")
                .query(q -> q.match(mq -> mq.field("result").query("correct"))),
        Void.class);
logger.info("response.hits.total.value = {}", response.hits().total().value());

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