# Different number of documents between stats and count

**URL:** https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283
**Category:** Elasticsearch
**Created:** [March 28, 2019, 9:28am UTC](https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283 "2019-03-28T09:28:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![apiras](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@apiras](https://discuss.elastic.co/u/apiras)
#### Post date: [March 28, 2019, 9:28am UTC](https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283/1 "2019-03-28T09:28:47Z")

</div>

Hi all,  
I get a different number of documents stored in an index invoking the endpoints /\_stats and /\_count. The same difference with v.6.5.0 and 6.7.0.

Let me an example.

With: GET /index1/\_count  
I get:

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

```

And 4 is the correct number of documents I posted on ES.

With: GET /index1/\_stats  
I get:

```
   {
      "_shards": {
        "total": 6,
        "successful": 3,
        "failed": 0
      },
      "_all": {
        "primaries": {
          "docs": {
            "count": 6,
            "deleted": 0
          },
          ...
          "indexing": {
            "index_total": 4,
            "index_time_in_millis": 148,
            "index_current": 0,
            "index_failed": 0,
            "delete_total": 0,
            "delete_time_in_millis": 0,
            "delete_current": 0,
            "noop_update_total": 0,
            "is_throttled": false,
            "throttle_time_in_millis": 0
          },
     ...
    },
    "total": {
      "docs": {
        "count": 6,
        "deleted": 0
      },
     ...
   }
 ...
}

```

A total of 6 documents instead of 4.

Does anyone know the reason?  
Thanks in advance.  
Andrea

---

<div class="post-metadata">

### Author: ![shanec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shanec/32/4004_2.png) [@shanec](https://discuss.elastic.co/u/shanec)
#### Post date: [April 5, 2019, 4:06pm UTC](https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283/2 "2019-04-05T16:06:35Z")

</div>

This type of difference can come from nested documents. For a simple example:

```auto
PUT /test/
{
  "mappings": {
   "_doc": {
      "properties": {
        "foo": {
          "type": "nested"
        }
      }
    }
  }
}
PUT /test/_doc/1
{
  "foo": {
    "bar": "baz"
  }
}
GET /test/_count
GET /test/_stats

```

You'll see `_count` returns 1 while `_stats` returns 2. [This is because](https://www.elastic.co/guide/en/elasticsearch/reference/current/nested.html):

> Internally, nested objects index each object in the array as a separate hidden document, meaning that each nested object can be queried independently of the others, with the [`nested` query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-nested-query.html)

And note that:

> Because nested documents are indexed as separate documents, they can only be accessed within the scope of the `nested` query, the `nested` / `reverse_nested` aggregations, or [nested inner hits](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html#nested-inner-hits).

---

<div class="post-metadata">

### Author: ![apiras](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@apiras](https://discuss.elastic.co/u/apiras)
#### Post date: [April 10, 2019, 2:51pm UTC](https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283/3 "2019-04-10T14:51:13Z")

</div>

Thanks!

---

<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: [May 8, 2019, 2:51pm UTC](https://discuss.elastic.co/t/different-number-of-documents-between-stats-and-count/174283/4 "2019-05-08T14:51:13Z")

</div>

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