# What's the difference between Id's query and Term Query when finding documents by “\_id”?

**URL:** https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523
**Category:** Elasticsearch
**Created:** [July 24, 2021, 7:04am UTC](https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523 "2021-07-24T07:04:05Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nishikant\_Tayade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishikant_tayade/32/84159_2.png) [@Nishikant\_Tayade](https://discuss.elastic.co/u/Nishikant_Tayade)
#### Post date: [July 24, 2021, 7:04am UTC](https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523/1 "2021-07-24T07:04:05Z")

</div>

I want to get document by "\_id", I have 3 choices:

```auto
GET document by "_id" GET order/_doc/001

Use Id's Query, GET order/_search { "query": { "ids" : { "values" : ["001"] } } } Though Id's query takes array of Id's but I will be using it to get only one document at a time, so just passing one id in "values" : ["001"]

Use Term Query GET order/_search { "query": {"term": {"_id" : "001"}}}

```

I want to know what's the difference between Id's query and Term Query, performance wise and any other points that I should be aware of?

Which one I should choose (between Id's and Term Query)?

Any help is much appreciated:)

UPDATE: Got the answer Please check [https://stackoverflow.com/questions/68507765/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-b](https://stackoverflow.com/questions/68507765/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-b)

---

<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: [July 24, 2021, 7:07am UTC](https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523/2 "2021-07-24T07:07:27Z")

</div>

I would always recommend the first option as it automatically get routed to the correct shard only. I do not know if there is a difference between the other two but they both query all shards in the index as far as I know.

---

<div class="post-metadata">

### Author: ![Nishikant\_Tayade](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nishikant_tayade/32/84159_2.png) [@Nishikant\_Tayade](https://discuss.elastic.co/u/Nishikant_Tayade)
#### Post date: [July 24, 2021, 7:11am UTC](https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523/3 "2021-07-24T07:11:39Z")

</div>

I can not use the first option in my case, as I am using alias(named "order") and my alias is pointing towards multiple indices (i.e index "order\_2020" and "order\_2021").

In these case, the first option **throws exception saying that alias is pointing towards multiple index** , cant perform operation on single index.

---

<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 21, 2021, 7:11am UTC](https://discuss.elastic.co/t/whats-the-difference-between-ids-query-and-term-query-when-finding-documents-by-id/279523/4 "2021-08-21T07:11:44Z")

</div>

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