Skip to content

Latest commit

 

History

History
42 lines (32 loc) · 917 Bytes

File metadata and controls

42 lines (32 loc) · 917 Bytes
endpoint count
lang java
es_version 9.3
client co.elastic.clients:elasticsearch-java:9.3.0

Elasticsearch 9.3 count endpoint (Java example)

Use client.count() to get the number of documents matching a query, without returning the documents themselves:

var response = client.count(c -> c
    .index("products")
    .query(q -> q
        .term(t -> t.field("category").value("electronics"))
    )
);

System.out.println("Electronics: " + response.count());

Counting all documents

Omit the query to count all documents in an index:

var response = client.count(c -> c.index("products"));
System.out.println("Total products: " + response.count());

Multiple indices

Pass multiple index names to count across indices:

var response = client.count(c -> c
    .index("products", "orders")
);
System.out.println("Total across indices: " + response.count());