---
type: api
title: Get a document count
description: **All methods and paths for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-cat-count
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/v8/operation/operation-cat-count
products:
  - Elasticsearch
---

# Get a document count


## Paths

- `GET` `/_cat/count/{index}`
- `GET` `/_cat/count`

#### Path parameters

- `index` (union string | string[]) — optional, leave it out to use `/_cat/count`
  A comma-separated list of data streams, indices, and aliases used to limit the request.
It supports wildcards (`*`).
To target all data streams and indices, omit this parameter or use `*` or `_all`.

## Description

Get quick access to a document count for a data stream, an index, or an entire cluster.
The document count only includes live documents, not deleted documents which have not yet been removed by the merge process.

IMPORTANT: CAT APIs are only intended for human consumption using the command line or Kibana console.
They are not intended for use by applications. For application consumption, use the count API.

## Required authorization

- Index privileges: `read`

## Authentication

- Api key: `Authorization: <value>`
  Elasticsearch APIs support key-based authentication.
  You must create an API key and use the encoded value in the request header.
  For example:
  
  
  ```
  curl -X GET "${ES_URL}/_cat/indices?v=true" \
    -H "Authorization: ApiKey ${API_KEY}"
  ```
  
  To get API keys, use the `/_security/api_key` APIs.
- Basic: `Authorization: Basic <credentials>`
- Bearer: `Authorization: Bearer <token>`
  Elasticsearch APIs support the use of bearer tokens in the `Authorization` HTTP header to authenticate with the API.
  For examples, refer to [Token-based authentication services](https://www.elastic.co/guide/en/elasticsearch/reference/current/token-authentication-services.html)

## Query string parameters

- `h` (union oneOf) — optional
  A comma-separated list of columns names to display. It supports simple wildcards.

Supported values include:
  - `epoch` (or `t`, `time`): The Unix epoch time in seconds since 1970-01-01 00:00:00.
  - `timestamp` (or `ts`, `hms`, `hhmmss`): The current time in HH:MM:SS format.
  - `count` (or `dc`, `docs.count`, `docsCount`): The document count in the cluster or index.
  Values: `epoch`, `t`, `time`, `timestamp`, `ts`, `hms`, `hhmmss`, `count`, `dc`, `docs.count`, `docsCount`
- `s` (union oneOf) — optional
  List of columns that determine how the table should be sorted.
Sorting defaults to ascending and can be changed by setting `:asc`
or `:desc` as a suffix to the column name.
  One of: `string[]` or `string`

## Response

`application/json`

Type: `object[]`

An array; each item has these fields:

- `epoch` (union)
  seconds since 1970-01-01 00:00:00
- `timestamp` (string)
  time in HH:MM:SS
- `count` (string)
  the document count
## Code examples

#### Console

```console
GET /_cat/count/my-index-000001?v=true&format=json
```

#### JavaScript

```javascript
const response = await client.cat.count({
  index: "my-index-000001",
  v: "true",
  format: "json",
});
```

#### Python

```python
resp = client.cat.count(
    index="my-index-000001",
    v=True,
    format="json",
)
```

#### curl

```curl
curl -X GET "$ELASTICSEARCH_URL/_cat/count/my-index-000001?v=true&format=json" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.cat().count();
```

#### PHP

```php
$resp = $client->cat()->count([
    "index" => "my-index-000001",
    "v" => "true",
    "format" => "json",
]);
```

#### Ruby

```ruby
response = client.cat.count(
  index: "my-index-000001",
  v: "true",
  format: "json"
)
```

## Response examples

#### Single data stream or index count

A successful response from `GET /_cat/count/my-index-000001?v=true&format=json`. It retrieves the document count for the `my-index-000001` data stream or index.

```json
[
  {
    "epoch": "1475868259",
    "timestamp": "15:24:20",
    "count": "120"
  }
]
```

#### All data streams and indices count

A successful response from `GET /_cat/count?v=true&format=json`. It retrieves the document count for all data streams and indices in the cluster.

```json
[
  {
    "epoch": "1475868259",
    "timestamp": "15:24:20",
    "count": "121"
  }
]
```

