I've two questions related to ElasticSearch.
1) Is there any way to specify that I want results with specific field sorted in descending order? An equivalt SQL query will be:
select * from table1 where a="b" order by myprimarykey desc;
2) How to get first and last(latest) record?
1) Elasticsearch has quite sophisticated Sorting API that allows you to control sort order. So, in elasticsearch, an equivalent to your MySql query would look like this:
{
"query" : {
"term" : { "a" : "b" }
},
"sort" : [
{ "myprimarykey" : "desc"} }
]
}
Sorting can also be specified on _search URI.
2) To retrieve the first and the last records you would need to perform two searches with desc
and asc
sort orders and retrieve one record for each. It's possible to combine both queries using Multi Search API.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With