# Inconsistency in the number of documents

**URL:** <https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129>\
**Category:** Elasticsearch\
**Created:** [December 13, 2022, 1:40pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129 "2022-12-13T13:40:49Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ariel\_Zach](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ariel\_Zach](https://discuss.elastic.co/u/Ariel_Zach)\
**Post date:** [December 13, 2022, 1:40pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/1 "2022-12-13T13:40:49Z")

</div>

I have an index with 2 shards which have 1600M documents each (~3200M total), but when I calculate a histogram, the sum does not give me the total number of documents, the result is much less, what is the reason?

---

<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:** [December 13, 2022, 2:37pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/2 "2022-12-13T14:37:54Z")

</div>

Please show an example of what you are seeing and the query you are running. Also provide information about which version of Elasticsearch you are using and how you determine the expected result.

---

<div class="post-metadata">

**Author:** ![Ariel\_Zach](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ariel\_Zach](https://discuss.elastic.co/u/Ariel_Zach)\
**Post date:** [December 13, 2022, 2:51pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/3 "2022-12-13T14:51:25Z")

</div>

Hi Christian,

ES 7.8

query:

```auto
{
  "size": 0,
  "aggs": {
    "count": {
      "date_histogram": {
        "field": "last_indexed",
        "interval": "year"
      }
    }
  }
}

```

result:

```auto
{
  "took": 4971,
  "timed_out": true,
  "_shards": {
    "total": 2,
    "successful": 2,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 10000,
      "relation": "gte"
    },
    "max_score": null,
    "hits": [

    ]
  },
  "aggregations": {
    "count": {
      "buckets": [
        {
          "key_as_string": "2022-01-01T00:00:00.000Z",
          "key": 1640995200000,
          "doc_count": 137538486
        }
      ]
    }
  }
}

```

index/\_count

```auto
{
  "count": 3151836577,
  "_shards": {
    "total": 2,
    "successful": 2,
    "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:** [December 13, 2022, 3:11pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/4 "2022-12-13T15:11:17Z")

</div>

Does all documents have the `last_indexed` field populated?

What does this return (not tested)?

```auto
POST index/_count
{
  "query": {
    "bool" : {
      "must_not" : {
        "exists": {
          "field": "last_indexed"
        }
      }
    }
  }
}

```

Are you using nested mappings?

What does the \_cat/indices API show for this index?

---

<div class="post-metadata">

**Author:** ![Ariel\_Zach](https://avatars.discourse-cdn.com/v4/letter/a/a88e57/32.png) [@Ariel\_Zach](https://discuss.elastic.co/u/Ariel_Zach)\
**Post date:** [December 13, 2022, 3:25pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/5 "2022-12-13T15:25:38Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> ```auto
> {
> "query": {
> "bool" : {
> "must_not" : {
> "exists": {
> "field": "last_indexed"
> }
> }
> }
> }
> }
> 
> ```

Yes, all documents have the field "last\_indexed".

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

```

\_cat/indices

```auto
{
  "health": "green",
  "status": "open",
  "index": "xxx",
  "uuid": "xxx",
  "pri": "2",
  "rep": "2",
  "docs.count": "3152018717",
  "docs.deleted": "62473287",
  "store.size": "1.5tb",
  "pri.store.size": "516.6gb"
}

```

We are not using nested documents.

---

<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:** [January 10, 2023, 3:26pm UTC](https://discuss.elastic.co/t/inconsistency-in-the-number-of-documents/321129/6 "2023-01-10T15:26:28Z")

</div>

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