# Why there are 20 documents diff (cat vs count)?

**URL:** https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341
**Category:** Elasticsearch
**Created:** [May 22, 2022, 4:11am UTC](https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341 "2022-05-22T04:11:20Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![asil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/asil/32/97607_2.png) [@asil](https://discuss.elastic.co/u/asil)
#### Post date: [May 22, 2022, 4:11am UTC](https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341/1 "2022-05-22T04:11:20Z")

</div>

I try to compare results of `count` and `cat` for the amount of documents and I'm getting different results:

`GET /my_index/_count` gives:

```auto
{
   "count": 4020199,
   "_shards": {
      "total": 1,
      "successful": 1,
      "skipped": 0,
      "failed": 0
   }
}

```

And `GET /_cat/indices` gives:

```auto
green open my_index 53IuNvZ1T4W_8u1U4bf7kb 1 1 8040418 0 27gb 13.5gb

```

When we compare the quantities we get that:

```auto
8040418 - 4020199 * 2 (one replica) = 20

```

Note: I used `refresh` command and there is no change.

So where are that 20 loss documents ?

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [May 22, 2022, 3:34pm UTC](https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341/2 "2022-05-22T15:34:53Z")

</div>

Hmm you have something odd going on...

These 2 commands should return the exact same number you do not need to multiply the count by number of replicas etc... the `_count` returns the number of document's irregardless of the replicas.

I picked a random index not the document count is `10034437` in both.

```auto
GET /_cat/indices/filebeat-7.15.2-2022.05.16-000168?v

health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
green open filebeat-7.15.2-2022.05.16-000168 qIO3tHowQtyIytZmqC62Lw 1 1 10034437 0 8.5gb 4.2gb

GET /filebeat-7.15.2-2022.05.16-000168/_count

{
  "count" : 10034437,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  }
}

```

---

<div class="post-metadata">

### Author: ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)
#### Post date: [May 22, 2022, 3:50pm UTC](https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341/3 "2022-05-22T15:50:16Z")

</div>

Can you share the output of the cat shards API for the index as well as the mappings for it? Are you by any chance using nested mappings?

If I remember correctly the count API returns the number of documents irrespective of the number of nested documents while the cat API includes nested documents as these count against the lucene shard limit. If this is the case and your documents mostly have 1 nested document but some have a higher or lower value, that may explain the difference.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [June 19, 2022, 3:50pm UTC](https://discuss.elastic.co/t/why-there-are-20-documents-diff-cat-vs-count/305341/4 "2022-06-19T15:50:42Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
