Is ID query faster than terms?

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?

@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.

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