Need to get latest 2 records


i need a query to fetch last and 2nd last record entered the index.

What should be the query other than putting size: 2 after sorting and all?


Do you have a timestamp in your document?

yes its there

So a sort on timestamp with size=2 should work, right?

it's working but another way.....

So? Is that ok?

is this is not the efficient way,
we are extracting all the documents and just displaying the top one (or two).
how to write a query which just extracts only these 2 records?

I don't understand. Why is this not efficient? What is the query you wrote?

this is not efficient coz query is fetching ALL the records but displaying only 1.
is it possible that the query only will fetch 1 record from the index (1 or 2 records)

this is according to me,
please let me know if i am not correct on this.

This is wrong. Just give it a try and if it's too slow, share what you did.

And if you want it to be super fast, use

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