# Should I route "get by \_id" queries to improve performance?

**URL:** <https://discuss.elastic.co/t/should-i-route-get-by-id-queries-to-improve-performance/277046>\
**Category:** Elasticsearch\
**Created:** [June 25, 2021, 11:02am UTC](https://discuss.elastic.co/t/should-i-route-get-by-id-queries-to-improve-performance/277046 "2021-06-25T11:02:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexander\_Gamanyuk1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexander_gamanyuk1/32/87063_2.png) [@Alexander\_Gamanyuk1](https://discuss.elastic.co/u/Alexander_Gamanyuk1)\
**Post date:** [June 25, 2021, 11:02am UTC](https://discuss.elastic.co/t/should-i-route-get-by-id-queries-to-improve-performance/277046/1 "2021-06-25T11:02:52Z")

</div>

I have an Elasticsearch index with hundreds of millions of documents that is used mostly for the "get by id" queries.

I consider adding a route to documents when indexing. The route will be a random number from 0 to 9.

Later this route will be in an URL with the document id, it that will be used to get the document. Currently I have only document ids in the [URLs](https://tarta.ai/j/xFrlQXoB5JkM4hVkY9eB-uipath-platform-architect-in-reston-virginia) but plan to add routes as well. The new URL will look like this [https://tarta.ai/](https://tarta.ai/) j/ [route] /[doc id].

I'm wondering will it decrease the time needed to find a document in the index? My suggestion is that Elasticsearch in this case won't look for a document in all the shards but instead will look only in the shards with this particular route.

Some specs:

- index size is 110gb.
- the number of docs is 36m but we're adding hundreds of thousands every day.
- 5 shards.
- 16GB RAM and 2 core vm with a 1t SSD.

---

<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:** [June 25, 2021, 12:33pm UTC](https://discuss.elastic.co/t/should-i-route-get-by-id-queries-to-improve-performance/277046/2 "2021-06-25T12:33:17Z")

</div>

The document ID defines which shard the document resides in so if you do a `GET <index>/<type>/<id>` only a single shard will be queried. Your approach will therefore as far as I can see add complexity while not improving performance at all.

---

<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 23, 2021, 12:34pm UTC](https://discuss.elastic.co/t/should-i-route-get-by-id-queries-to-improve-performance/277046/3 "2021-07-23T12:34:13Z")

</div>

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