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

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

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

1 Like

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.

1 Like

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.

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