# Performance - Querying against \_id versus \_source content

**URL:** <https://discuss.elastic.co/t/performance-querying-against-id-versus-source-content/167862>\
**Category:** Elasticsearch\
**Created:** [February 11, 2019, 1:18pm UTC](https://discuss.elastic.co/t/performance-querying-against-id-versus-source-content/167862 "2019-02-11T13:18:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![freaka](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/freaka/32/41962_2.png) [@freaka](https://discuss.elastic.co/u/freaka)\
**Post date:** [February 11, 2019, 1:18pm UTC](https://discuss.elastic.co/t/performance-querying-against-id-versus-source-content/167862/1 "2019-02-11T13:18:14Z")

</div>

Hi,

I have read that indexing is faster when no id is specified (elasticsearch does not have to check for duplicate).  
However, is it relevant to index with a chosen \_id if this document has to be retrieved multiple times in the future? Is it faster to get a document by \_id rather than having an "id" field in the \_source section ?

Thanks,

edit: I cannot add a tag like "performance" therefore I put that in the title 😕

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [February 15, 2019, 7:57pm UTC](https://discuss.elastic.co/t/performance-querying-against-id-versus-source-content/167862/2 "2019-02-15T19:57:01Z")

</div>

It's faster to `GET` a document directly by ID rather than having to search for it. Predominantly because we can go directly to the appropriate shard and lookup the document, whereas a search has to touch all the shards in parallel and lookup the term to find the document. It probably won't be exceptionally slow, but the get-by-ID should always be faster.

I wouldn't worry too much about the performance of autogenerated ID vs user-defined ID. There's a bit of a difference, but it isn't immense. I tell people that if you have a natural ID for a document... use that because it's likely you'll want to get-by-ID at some point. But if there's no natural ID, then go ahead and use the autogenerated version.

---

<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:** [March 15, 2019, 7:57pm UTC](https://discuss.elastic.co/t/performance-querying-against-id-versus-source-content/167862/3 "2019-03-15T19:57:10Z")

</div>

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