Reputation: 525
I'm using NodeJS to find the first and last document in Elasticsearch Index.
client.search({index: 'test',size:1,sort:[{"_timestamp":{"order":
"desc"}}]},function(err,resp,status) { console.log("data",resp);
});
Where am I going wrong?
Upvotes: 0
Views: 1080
Reputation: 4000
You should use a query to match all docs and then sort them :
client.search({
index: 'test',
query: {
"match_all": {}
},
sort: [{
"_timestamp": {
"order":
"desc"
}
}],
size: 1
}, function (err, resp, status) {
console.log("data", resp);
});
Upvotes: 2