If you are looking for a document based on id, what is faster and why:
/index/_doc/id -> i would think it is, but maybe under covers it is the same as
/index/_search {"query" : {"terms" : { "_id": .....
any reason one would prefer one of these vs the other and vise versa?
Thank you.
One is not syntactic sugar for the other. The index/_doc/id
call is real-time, in that you can create doc id
and then read it back instantly. The _search
API behaves differently, and will only surface your doc after it's visible in the segment it has been written to based on the refresh_interval
. I'd expect the simple id lookup to be faster as it's just doing a lot less that search.
This is not completely true because a realtime GET will execute an (internal) refresh if the document was recently modified, which may be expensive. You can of course disable the realtime behaviour and then I think I'd also expect it to be a little cheaper than a terms query (or the more-specialized IDs query). It's worth benchmarking, however, as these kinds of question are subtle and may depend on the details of the actual workload.
A GET by doc_id routes the request to exactly one shard whereas a search is broadcast to all shards.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.