For some reason, when I trying to search and sort from an index
This works:
GET indexName/_search
{
"sort": [{
"_uid": { "order": "desc" }
}],
"size": 1
}
But, when using node js like this:
elasticClient.search({
index: indexName,
type: id,
sort: [{ "_uid": { "order": "desc" } }],
size: 1
})
It returns an error:
No mapping found for [[object Object]] in order to sort on
status :400
I've tried JSON.stringify
and all kind of other things, but none of them works
Please, can anyone help me?
Use the sort() method to sort the result in ascending or descending order. The sort() method takes one parameter, an object defining the sorting order.
Elasticsearch lets you search through vast amounts of data, whether you're implementing real-time search experiences or doing in-depth data analysis. In this tutorial, you'll learn how to integrate Elasticsearch into your Node. js app.
In Elasticsearch, the relevance score is represented by the floating-point number returned in the search results as the _score , so the default sort order is _score descending.
Try this instead:
elasticClient.search({
index: indexName,
type: id,
body: {
sort: [{ "_uid": { "order": "desc" } }],
size: 1,
query: { match_all: {}}
}
})
This also works with the square brackets around it so you can add more than one sort criteria like ['_uid:desc', 'id:asc']
elasticClient.search({
index: indexName,
sort: ['_uid:desc'],
type: id,
body: {
size: 1,
query: { match_all: {}}
}
})
This also works :
elasticClient.search({
index: indexName,
sort: '_uid:desc',
type: id,
body: {
size: 1,
query: { match_all: {}}
}
})
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