# Most efficient way to get all ids of a type

**URL:** <https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111>\
**Category:** Elasticsearch\
**Created:** [April 12, 2016, 11:07am UTC](https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111 "2016-04-12T11:07:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![living\_jordi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/living_jordi/32/61363_2.png) [@living\_jordi](https://discuss.elastic.co/u/living_jordi)\
**Post date:** [April 12, 2016, 11:07am UTC](https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111/1 "2016-04-12T11:07:47Z")

</div>

What's the best way in order to get all ids of a type using Java API?

Thanks.

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [April 12, 2016, 11:11am UTC](https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111/2 "2016-04-12T11:11:22Z")

</div>

Hi,

you can use the [Scroll API](https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-scrolling.html) together with a match\_all query. But the better question is why you just need the ids.

Daniel

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 12, 2016, 11:35am UTC](https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111/3 "2016-04-12T11:35:29Z")

</div>

But it is good to remember that this isn't what Elasticsearch is good at - those \_ids are stored with the \_source so they can be slower to fetch. Elasticsearch's aggregations are fast because they use a column store (doc values). \_id doesn't have that.

If performance is good enough for you then it is fine, but if it isn't then you are often better off thinking of reworking what you want to do as some kind of aggregation.

---

<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:00pm UTC](https://discuss.elastic.co/t/most-efficient-way-to-get-all-ids-of-a-type/47111/4 "2017-07-05T23:00:12Z")

</div>


