Sort is broken
See original GitHub issueRunning a search in Node with a sort is broken. I can run the exact same query with curl and it returns correctly. It looks like it may have something to do with the way the sort array is getting parsed as you can see below in the trace. I searched all over to see if I was doing something wrong, but maybe someone more skilled than me can take a look.
function runSearch() {
esC.search({
"query":{
"bool":{
"must":[{
"query_string":{
"default_field":"UPDATE.user_id","query":"2f9633f8-3cc5-344b-bf71-fe0f78ae46da"}
}]
}
},
"from":0,
"size":50,
"sort":[{ "timestamp" : {"order" : "desc", "ignore_unmapped" : true}}]
}, function (err, res) {
console.log(res);
});
}
Elasticsearch DEBUG: 2014-09-19T03:33:04Z
starting request { method: 'POST',
path: '/_search',
query:
{ query: { bool: [Object] },
from: 0,
size: 50,
sort: '[object Object]' } }
Elasticsearch TRACE: 2014-09-19T03:33:04Z
-> POST http://10.0.200.95:9200/_search?query=&from=0&size=50&sort=%5Bobject%20Object%5D
<- 400
{
"error": "SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[b-srgZ7-S4WD5CSq5njRpQ][feed][0]: RemoteTransportException[[Curtis][inet[/10.0.200.94:9300]][search/phase/query]]; nested: SearchParseException[[feed][0]: from[0],size[50]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":50,\"sort\":[{\"[object Object]\":{}}]}]]]; nested: SearchParseException[[feed][0]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }{[V31kXWvmSlyVGDW543VaJA][feed][1]: SearchParseException[[feed][1]: from[0],size[50]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":50,\"sort\":[{\"[object Object]\":{}}]}]]]; nested: SearchParseException[[feed][1]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }{[V31kXWvmSlyVGDW543VaJA][feed][2]: SearchParseException[[feed][2]: from[0],size[50]: Parse Failure [Failed to parse source [{\"from\":0,\"size\":50,\"sort\":[{\"[object Object]\":{}}]}]]]; nested: SearchParseException[[feed][2]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }]",
"status": 400
}
Elasticsearch DEBUG: 2014-09-19T03:33:04Z
Request complete
{ error: 'SearchPhaseExecutionException[Failed to execute phase [query], all shards failed; shardFailures {[b-srgZ7-S4WD5CSq5njRpQ][feed][0]: RemoteTransportException[[Curtis][inet[/10.0.200.94:9300]][search/phase/query]]; nested: SearchParseException[[feed][0]: from[0],size[50]: Parse Failure [Failed to parse source [{"from":0,"size":50,"sort":[{"[object Object]":{}}]}]]]; nested: SearchParseException[[feed][0]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }{[V31kXWvmSlyVGDW543VaJA][feed][1]: SearchParseException[[feed][1]: from[0],size[50]: Parse Failure [Failed to parse source [{"from":0,"size":50,"sort":[{"[object Object]":{}}]}]]]; nested: SearchParseException[[feed][1]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }{[V31kXWvmSlyVGDW543VaJA][feed][2]: SearchParseException[[feed][2]: from[0],size[50]: Parse Failure [Failed to parse source [{"from":0,"size":50,"sort":[{"[object Object]":{}}]}]]]; nested: SearchParseException[[feed][2]: from[0],size[50]: Parse Failure [No mapping found for [[object Object]] in order to sort on]]; }]',
status: 400 }
Issue Analytics
- State:
- Created 9 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Sorting by top is still broken and NOT RESOLVED - Reddit
Any update? Sorting by year is still broken for me, sorting by month seems to be fixed tho.
Read more >Sort broken for date · Issue #1412 · mikefarah/yq - GitHub
I am trying to sort by a dictionary by a value that contains numbers. The sorting does not work, regardless of whether I...
Read more >Sort not working the way its supposed to. - Microsoft Community
I have a spreadsheet with 8 columns and 1264 rows. I'm trying to do a simple sort on one of the columns. I...
Read more >Array sort is not working correctly in JavaScript - Stack Overflow
You sorting is failing because your comparison function does not meet the specifications for Array.sort :.
Read more >Sorting is broken | WordPress.org
When sorting by last name, I'm getting a result that looks like this: Edwards Edwards Farley Ertel Fagin etc. There's inconsistent results when...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think this is still broken. Passing an object in as the elasticsearch rest api supports it does not get parsed to JSON correctly. Adding it to the “body” of the query and your results are not sorted. the sort field does work with simple strings passed in the array something like:
but not:
Can you please copy old example? The link is broken and dont work anymore.
upd. Here it the schematic code:
It’s strange, that the official document contains wrong description https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/6.x/api-reference.html#_search. For me, sort on the top level work only if i pass string or array of strings without direction.