139 lines
3.4 KiB
Markdown
139 lines
3.4 KiB
Markdown
---
|
|
layout: default
|
|
title: CAT count
|
|
parent: CAT APIs
|
|
nav_order: 10
|
|
has_children: false
|
|
redirect_from:
|
|
- /opensearch/rest-api/cat/cat-count/
|
|
|
|
---
|
|
|
|
# CAT Count API
|
|
**Introduced 1.0**
|
|
{: .label .label-purple }
|
|
|
|
The CAT count operation lists the number of documents in your cluster.
|
|
|
|
The count includes only live documents. Documents that you deleted are not counted, even if they have not yet been removed from disk by a segment merge. To see the number of deleted documents in each index, use the [CAT Indices API]({{site.url}}{{site.baseurl}}/api-reference/cat/cat-indices/).
|
|
|
|
|
|
<!-- spec_insert_start
|
|
api: cat.count
|
|
component: endpoints
|
|
-->
|
|
## Endpoints
|
|
```json
|
|
GET /_cat/count
|
|
GET /_cat/count/{index}
|
|
```
|
|
<!-- spec_insert_end -->
|
|
|
|
|
|
<!-- spec_insert_start
|
|
api: cat.count
|
|
component: query_parameters
|
|
columns: Parameter, Data type, Description, Default
|
|
include_deprecated: false
|
|
-->
|
|
## Query parameters
|
|
|
|
The following table lists the available query parameters. All query parameters are optional.
|
|
|
|
| Parameter | Data type | Description | Default |
|
|
| :--- | :--- | :--- | :--- |
|
|
| `format` | String | A short version of the `Accept` header, such as `json` or `yaml`. <br> Valid values are: `cbor`, `json`, `smile`, `text`, and `yaml`. | `text` |
|
|
| `h` | List | A comma-separated list of column names to display. | N/A |
|
|
| `help` | Boolean | Returns help information. | `false` |
|
|
| `limit` | Integer | The maximum number of rows to return. Must be greater than 0. Applied after sorting (`s`). | N/A |
|
|
| `s` | List | A comma-separated list of column names or column aliases to sort by. | N/A |
|
|
| `v` | Boolean | Enables verbose mode, which displays column headers. | `false` |
|
|
|
|
<!-- spec_insert_end -->
|
|
|
|
## Example requests
|
|
|
|
<!-- spec_insert_start
|
|
component: example_code
|
|
rest: GET /_cat/count?v
|
|
-->
|
|
{% capture step1_rest %}
|
|
GET /_cat/count?v
|
|
{% endcapture %}
|
|
|
|
{% capture step1_python %}
|
|
|
|
|
|
response = client.cat.count(
|
|
params = { "v": "true" }
|
|
)
|
|
|
|
{% endcapture %}
|
|
|
|
{% include code-block.html
|
|
rest=step1_rest
|
|
python=step1_python %}
|
|
<!-- spec_insert_end -->
|
|
|
|
To see the number of documents in a specific index or alias, add the index or alias name after your query:
|
|
|
|
<!-- spec_insert_start
|
|
component: example_code
|
|
rest: GET /_cat/count/<index_or_alias>?v
|
|
-->
|
|
{% capture step1_rest %}
|
|
GET /_cat/count/<index_or_alias>?v
|
|
{% endcapture %}
|
|
|
|
{% capture step1_python %}
|
|
|
|
|
|
response = client.cat.count(
|
|
index = "<index_or_alias>",
|
|
params = { "v": "true" }
|
|
)
|
|
|
|
{% endcapture %}
|
|
|
|
{% include code-block.html
|
|
rest=step1_rest
|
|
python=step1_python %}
|
|
<!-- spec_insert_end -->
|
|
|
|
If you want to get information for more than one index or alias, separate the index or alias names with commas:
|
|
|
|
<!-- spec_insert_start
|
|
component: example_code
|
|
rest: GET /_cat/count/index_or_alias_1,index_or_alias_2,index_or_alias_3
|
|
-->
|
|
{% capture step1_rest %}
|
|
GET /_cat/count/index_or_alias_1,index_or_alias_2,index_or_alias_3
|
|
{% endcapture %}
|
|
|
|
{% capture step1_python %}
|
|
|
|
|
|
response = client.cat.count(
|
|
index = "index_or_alias_1,index_or_alias_2,index_or_alias_3"
|
|
)
|
|
|
|
{% endcapture %}
|
|
|
|
{% include code-block.html
|
|
rest=step1_rest
|
|
python=step1_python %}
|
|
<!-- spec_insert_end -->
|
|
|
|
## Example response
|
|
|
|
The following response shows the overall document count as 1625:
|
|
|
|
```json
|
|
epoch | timestamp | count
|
|
1624237738 | 01:08:58 | 1625
|
|
```
|
|
|
|
## Required permissions
|
|
|
|
If you use the Security plugin, make sure you have the appropriate permissions: `indices:data/read/search`.
|