Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 835 Bytes

File metadata and controls

39 lines (29 loc) · 835 Bytes
endpoint count
lang python
es_version 9.3
client elasticsearch==9.3.0

Elasticsearch 9.3 count endpoint (Python example)

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

response = client.count(
    index="products",
    query={"term": {"category": "electronics"}},
)

print(f"Electronics: {response['count']}")

Counting all documents

Omit the query parameter to count all documents in an index:

response = client.count(index="products")
print(f"Total products: {response['count']}")

Multiple indices

Pass a comma-separated string or a list of index names to count across multiple indices:

response = client.count(index=["products", "orders"])
print(f"Total across indices: {response['count']}")