# Query for counting docs per type?

**URL:** https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004
**Category:** Elasticsearch
**Created:** [October 26, 2015, 5:01pm UTC](https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004 "2015-10-26T17:01:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)
#### Post date: [October 26, 2015, 5:01pm UTC](https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004/1 "2015-10-26T17:01:18Z")

</div>

We are using the following request, to return the number of documents per doc-type. But it just lists all types with more then zero documents. How can we also return all types that have no document yet?

```
GET /myIndex/_search?search_type=count
{
    "aggs": {
        "count_by_type": {
            "terms": {
                "field": "_type"
            }
        }
    }
}
```

---

<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: [October 27, 2015, 5:33am UTC](https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004/2 "2015-10-27T05:33:35Z")

</div>

You can't do this because there can never be a doc without a `_type`.

---

<div class="post-metadata">

### Author: ![mos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mos/32/4898_2.png) [@mos](https://discuss.elastic.co/u/mos)
#### Post date: [October 27, 2015, 8:17am UTC](https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004/3 "2015-10-27T08:17:11Z")

</div>

Ok, so I need to read all types separately, to catch those with zero hits? Is there a simple query to read just all available types per index. (\_mapping is to much information)

---

<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:42pm UTC](https://discuss.elastic.co/t/query-for-counting-docs-per-type/33004/4 "2017-07-05T23:42:30Z")

</div>


