# Different Doc count after reindexing

**URL:** <https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826>\
**Category:** Elasticsearch\
**Created:** [January 10, 2023, 12:02pm UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826 "2023-01-10T12:02:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cr\_168328](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cr\_168328](https://discuss.elastic.co/u/cr_168328)\
**Post date:** [January 10, 2023, 12:02pm UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/1 "2023-01-10T12:02:08Z")

</div>

I have an index ` user1`. To add some fields, I created a new index and did reindexing using the query:

```auto
POST /_reindex?scroll=30m
{
  "source": {
    "index": "user1"
  },
  "dest": {
    "index": "user2"
  }
}

```

After reindexing is complete, `GET _cat/indices` gives the following result for the 2 indices:

```auto
yellow open user1 _tg9nbGWSreKBBsa7E0XwQ 5 1 298934 47108 36.7gb 36.7gb 
yellow open user2 ne1m5aWDR5K064qCo0awKw 5 1 314441 0 25.5gb 25.5gb

```

But `_count` query on both the indices give the same value.

Why is `Docs count` more and `Storage size` less for the new index during `GET _cat/indices` ?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 10, 2023, 4:19pm UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/2 "2023-01-10T16:19:36Z")

</div>

> [@cr\_168328](#):
>
> Why is `Docs count` more

No idea. May be you had existing data before? Or you changed the mapping and now are using nested documents?

> [@cr\_168328](#):
>
> `Storage size` less

Because you probably have less segments, no updates, better compression...

---

<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:** [January 10, 2023, 4:23pm UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/3 "2023-01-10T16:23:49Z")

</div>

Assuming mappings are the same it seems like you have updated and/or deleted documents in the user1 index. This takes up space as old or deleted documents are not immediately removed. I suspect this explains the difference in size and count.

---

<div class="post-metadata">

**Author:** ![cr\_168328](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cr\_168328](https://discuss.elastic.co/u/cr_168328)\
**Post date:** [January 11, 2023, 4:27am UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/4 "2023-01-11T04:27:08Z")

</div>

> [@dadoonet](#):
>
> May be you had existing data before?

There was no existing data. The index was newly created for reindexing.

> [@dadoonet](#):
>
> Or you changed the mapping and now are using nested documents?

Yes. I changed the mapping and created few more fields, which includes nested fields also.

Could you please explain how adding nested fields increase the Docs count (while `_count` query shows the same count for both indices)?

---

<div class="post-metadata">

**Author:** ![cr\_168328](https://avatars.discourse-cdn.com/v4/letter/c/76d3ee/32.png) [@cr\_168328](https://discuss.elastic.co/u/cr_168328)\
**Post date:** [January 11, 2023, 4:31am UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/5 "2023-01-11T04:31:27Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> it seems like you have updated and/or deleted documents in the user1 index

I haven't updated/deleted any documents.

> [@Christian\_Dahlqvist](#):
>
> Assuming mappings are the same

Mappings are not same. I have updated the mapping and added few more fields including nested fields in the new index. How does it cause the difference in count?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 11, 2023, 8:10am UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/6 "2023-01-11T08:10:11Z")

</div>

Each nested document is indexed as a document in Lucene. That's why you have more documents than in the source index.

---

<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:** [February 8, 2023, 8:10am UTC](https://discuss.elastic.co/t/different-doc-count-after-reindexing/322826/7 "2023-02-08T08:10:55Z")

</div>

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