---
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/operation/operation-cat-count
resource: https://www.elastic.co/elastic/docs-builder/docs/4493/api/doc/elasticsearch/operation/operation-cat-count
products:
  - Elasticsearch
---

# Get a document count


## Paths

- `POST` (also `GET`) `/_cat/count/{index}`
- `POST` (also `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.

NOTE: Starting in Elasticsearch 9.3.0, this endpoint also supports the `POST` method. This is primarily intended for project routing in serverless environments.

## 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/docs/deploy-manage/users-roles/cluster-or-deployment-auth/token-based-authentication-services)

## 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`
- `format` (string · default: text) — optional
  Specifies the format to return the columnar data in, can be set to
`text`, `json`, `cbor`, `yaml`, or `smile`.
- `help` (boolean · default: false) — optional
  When set to `true` will output available columns. This option
can't be combined with any other query string option.
- `v` (boolean · default: false) — optional
  When set to `true` will enable verbose output.
- `bytes` (enum) — optional
  Sets the units for columns that contain a byte-size value.
Note that byte-size value units work in terms of powers of 1024. For instance `1kb` means 1024 bytes, not 1000 bytes.
If omitted, byte-size values are rendered with a suffix such as `kb`, `mb`, or `gb`, chosen such that the numeric value of the column is as small as possible whilst still being at least `1.0`.
If given, byte-size values are rendered as an integer with no suffix, representing the value of the column in the chosen unit.
Values that are not an exact multiple of the chosen unit are rounded down.
  Values: `b`, `kb`, `mb`, `gb`, `tb`, `pb`
- `time` (enum) — optional
  Sets the units for columns that contain a time duration.
If omitted, time duration values are rendered with a suffix such as `ms`, `s`, `m` or `h`, chosen such that the numeric value of the column is as small as possible whilst still being at least `1.0`.
If given, time duration values are rendered as an integer with no suffix.
Values that are not an exact multiple of the chosen unit are rounded down.
  Values: `nanos`, `micros`, `ms`, `s`, `m`, `h`, `d`

## Request body

`application/json`

Type: `object`


## 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
POST /_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 POST "$ELASTICSEARCH_URL/_cat/count/my-index-000001?v=true&format=json" \
  -H "Authorization: ApiKey $ELASTIC_API_KEY"
```

#### Java

```java
client.cat().count(c -> c
    .index("my-index-000001")
);
```

#### 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"
  }
]
```

