Count search results

  • POST also GET /{index}/_count
  • POST also GET /_count

Get the number of documents matching a query.

The query can be provided either by using a simple query string as a parameter, or by defining Query DSL within the request body. The query is optional. When no query is provided, the API uses match_all to count all the documents.

The count API supports multi-target syntax. You can run a single count API search across multiple data streams and indices.

The operation is broadcast across all shards. For each shard ID group, a replica is chosen and the search is run against it. This means that replicas increase the scalability of the count.

  • Index privileges: read

Path Parameters

index union IndexName | [] IndexName optional

A comma-separated list of data streams, indices, and aliases to search. It supports wildcards (*). To search all data streams and indices, omit this parameter or use * or _all.

Leave it out to use /_count.

Request

query {} QueryContainer

Defines the search query using Query DSL. A request body query cannot be used with the q query string parameter.

Response