# Number of documents in an index

**URL:** <https://discuss.elastic.co/t/number-of-documents-in-an-index/44562>\
**Category:** Elasticsearch\
**Created:** [March 16, 2016, 2:13pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562 "2016-03-16T14:13:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 16, 2016, 2:13pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/1 "2016-03-16T14:13:41Z")

</div>

Hi,

I'm doing some load testing and I found something strange on ElasticSearch (2.2.0).

I feed a single index with 104.690.000 documents. This index has only 2 shards.

When I check the output of `/_cat/indices`, I get this:

`green open customer-data-100m-v1 2 1 104690000 0 171.2gb 88.3gb`

But when I do a `GET /customer-data-100m-v1/customer/_count`, I get half number of documents:

`{ "count": 52345000, "_shards": { "total": 2, "successful": 2, "failed": 0 } }`

Is this somehow related to the number of shards? Shouldn't I get the same count?

---

<div class="post-metadata">

**Author:** ![evolgas](https://avatars.discourse-cdn.com/v4/letter/e/dfb087/32.png) [@evolgas](https://discuss.elastic.co/u/evolgas)\
**Post date:** [March 16, 2016, 3:10pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/2 "2016-03-16T15:10:07Z")

</div>

What happens if you `GET /customer-data-100m-v1/_count` instead of `GET /customer-data-100m-v1/customer/_count`

---

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 16, 2016, 4:28pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/3 "2016-03-16T16:28:55Z")

</div>

I get the same output.

---

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 16, 2016, 4:33pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/4 "2016-03-16T16:33:25Z")

</div>

So, it looks like it's not related to the number of shards, because I loaded another index with +100mi docs, but now with 4 shards, and I also get half count.

`green open customer-data-100m-4shards-v1 4 1 107180000 0 171gb 85.5gb`

`{ "count": 53590000, "_shards": { "total": 4, "successful": 4, "failed": 0 } }`

---

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [March 16, 2016, 5:36pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/5 "2016-03-16T17:36:28Z")

</div>

> [@evolgas](#):
>
> GET /customer-data-100m-v1/

How about

```auto
GET /customer-data-100m-v1/_stats

```

---

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 16, 2016, 5:43pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/6 "2016-03-16T17:43:59Z")

</div>

I deleted a few docs to try something else, so here are the updated results, including the part of the output of `/_stats`

```auto
green open customer-data-100m-v1 2 1 104677426 12574 170.9gb 88gb 

```

```auto
{
   "count": 52338713,
   "_shards": {
      "total": 2,
      "successful": 2,
      "failed": 0
   }
}

```

The the output of `/customer-data-100m-v1/_stats` is at [http://pastebin.com/raw/YpZn06jK](http://pastebin.com/raw/YpZn06jK)

---

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [March 16, 2016, 5:48pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/7 "2016-03-16T17:48:37Z")

</div>

\_stats gave you the number you expected

```auto
"indices": {
      "customer-data-100m-v1": {
         "primaries": {
            "docs": {
               "count": 104677426,
               "deleted": 12574
            },

```

but it's strange that \_count did not give you the same number. I checked many of my indices, and all gave the same number for both \_count and \_stats

---

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 16, 2016, 5:51pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/8 "2016-03-16T17:51:00Z")

</div>

Yes, but what is `count` then?

```auto
{
   "count": 52338713,

```

---

<div class="post-metadata">

**Author:** ![anhlqn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anhlqn/32/5454_2.png) [@anhlqn](https://discuss.elastic.co/u/anhlqn)\
**Post date:** [March 16, 2016, 5:57pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/9 "2016-03-16T17:57:54Z")

</div>

You previous \_count showed a total of two shards while the \_stats showed 4 shards. Could you try

```auto
GET _cat/count/customer-data-100m-v1

```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 16, 2016, 8:17pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/10 "2016-03-16T20:17:01Z")

</div>

At an educated guess, `_cat` include replica documents while `_stats` doesn't.

---

<div class="post-metadata">

**Author:** ![hgfxng](https://avatars.discourse-cdn.com/v4/letter/h/aeb1de/32.png) [@hgfxng](https://discuss.elastic.co/u/hgfxng)\
**Post date:** [March 21, 2016, 4:03pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/11 "2016-03-21T16:03:34Z")

</div>

Hi,

here:

```auto
GET /_cat/count/customer-data-100m-v1

1458576068 17:01:08 52338713

```

---

<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:** [July 5, 2017, 11:06pm UTC](https://discuss.elastic.co/t/number-of-documents-in-an-index/44562/12 "2017-07-05T23:06:31Z")

</div>


