# Docs count on migration - difference between \`\_count\` and \`\_stats\`

**URL:** <https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620>\
**Category:** Elasticsearch\
**Created:** [March 18, 2024, 3:25pm UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620 "2024-03-18T15:25:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxxer/32/50472_2.png) [@maxxer](https://discuss.elastic.co/u/maxxer)\
**Post date:** [March 18, 2024, 3:25pm UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/1 "2024-03-18T15:25:40Z")

</div>

Hi.  
We're migrating from an on-premise Elasticsearch 7.17.10 to an Elastic-cloud 7.17.14 one. We are migrating using [`esm`](https://github.com/medcl/esm).

Everything seems fine, but we noticed some high-volume indexes have a `_count` very different from a) the number of documents managed by `esm` b) the total number of docs returned by `_stats` in `total > docs > count`. The latter, in the source environment has something like 380000 docs, while `_count` and `esm` report ~41521. When migrated, on the destination both `_count` and `_stats` return ~41521.

Searching around, I learnt `_stats` counts also nested documents. I have some indexes with nested docs and, apparently, they've been copied correctly.

So I'm puzzled to understand where this huge difference in docs count lies. And if, by any chance, if I can be confident all my data is being copied correctly. 😁

Thanks

---

<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:** [March 18, 2024, 6:37pm UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/2 "2024-03-18T18:37:38Z")

</div>

Check if the mapping is the same.

---

<div class="post-metadata">

**Author:** ![maxxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxxer/32/50472_2.png) [@maxxer](https://discuss.elastic.co/u/maxxer)\
**Post date:** [March 18, 2024, 8:36pm UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/3 "2024-03-18T20:36:15Z")

</div>

It's _almost_ the same... It should be, but there are small differences: some fields that were mapped as _float_ are _text_ on the new installation, a very small bunch of fields missing in the new.  
I know nothing about ES, but looks strange that these mapping differences could lead to such a magnitude gap between the two. Also because there are much more documents on the old, rather than on the new.

Side request: how can I obtain a `_count` list with all the indexes? From what I could understand, this is an ES-only endpoint, thus it cannot be queried from outside. I can do it on the on-prem install, but I didn't understand how to do the same with the elastic-cloud managed instance.

---

<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:** [March 19, 2024, 9:34am UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/4 "2024-03-19T09:34:55Z")

</div>

> [@maxxer](#):
>
> some fields that were mapped as _float_ are _text_ on the new installation

Why? You did not apply the same mapping?

> [@maxxer](#):
>
> how can I obtain a `_count` list with all the indexes?

Per index?

```auto
GET /*/_search
{
  "track_total_hits": true, 
  "size": 0,
  "aggs": {
    "index": {
      "terms": {
        "field": "_index"
      }
    }
  }
}

```

Or globally?

```auto
GET /*/_count

```

---

<div class="post-metadata">

**Author:** ![maxxer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maxxer/32/50472_2.png) [@maxxer](https://discuss.elastic.co/u/maxxer)\
**Post date:** [March 19, 2024, 10:13am UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/5 "2024-03-19T10:13:26Z")

</div>

> [@dadoonet](#):
>
> Why? You did not apply the same mapping?

Indexes were created with the wrong mapping, fixed it.

> [@dadoonet](#):
>
> Per index?

As said in the first post, I learnt `_search` and `_count` can return different results. I was looking for a way to obtain a list of all indexes with related `_count`. I haven't found the correct endpoint for this last call on our elastic-cloud instance.

---

<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:** [March 19, 2024, 10:24am UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/6 "2024-03-19T10:24:33Z")

</div>

> [@maxxer](#):
>
> As said in the first post, I learnt `_search` and `_count` can return different results.

Not sure about this. But if you run a `_refresh` before that should be the same values.

---

<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:** [April 16, 2024, 10:25am UTC](https://discuss.elastic.co/t/docs-count-on-migration-difference-between-count-and-stats/355620/7 "2024-04-16T10:25:19Z")

</div>

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