# Is ID query faster than terms?

**URL:** <https://discuss.elastic.co/t/is-id-query-faster-than-terms/242623>\
**Category:** Elasticsearch\
**Created:** [July 25, 2020, 9:47pm UTC](https://discuss.elastic.co/t/is-id-query-faster-than-terms/242623 "2020-07-25T21:47:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cynosureabu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cynosureabu/32/47196_2.png) [@cynosureabu](https://discuss.elastic.co/u/cynosureabu)\
**Post date:** [July 25, 2020, 9:47pm UTC](https://discuss.elastic.co/t/is-id-query-faster-than-terms/242623/1 "2020-07-25T21:47:15Z")

</div>

So I am trying to save comment objects to ES, should I just use comment\_id as the native \_id field? Later if I am to retrieve 500 comments, will query by ids  
{  
"query": {  
"ids" : {  
"values" : [id1, id2, ...]  
}  
}  
}  
, faster than terms: {id: [id1,id2,]}

or it is the same?

---

<div class="post-metadata">

**Author:** ![Vinayak\_Sapre](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinayak_sapre/32/45939_2.png) [@Vinayak\_Sapre](https://discuss.elastic.co/u/Vinayak_Sapre)\
**Post date:** [July 26, 2020, 4:53am UTC](https://discuss.elastic.co/t/is-id-query-faster-than-terms/242623/2 "2020-07-26T04:53:51Z")

</div>

@cynosureabu  
ES guarantees uniqueness of \_id in the index. If values are stored as id field you can store duplicates. Two options are not technically same.

While getting a single document by \_id `localhost:9200/<index>/<_id>`, ES can determine the shard this id belongs to. It will be optimal compared to running a query which will be sent to all shards

If you are searching multiple ids, \_id and id field should perform same.

---

<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:** [August 23, 2020, 4:54am UTC](https://discuss.elastic.co/t/is-id-query-faster-than-terms/242623/3 "2020-08-23T04:54:04Z")

</div>

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