我與ElasticSearch工作,並試圖將一個特定範圍內對結果進行排序。 這是我的要求是我希望搜索結果具有特定範圍的工資並對其進行排序。 因此,這裏是我想查詢:如何對一個範圍內的搜索結果進行排序?
curl -XPOST 'localhost:9200/employee/_search?pretty' -d '
{
"query": { "match_all": {} },
"sort" : {
salary : {
"range" : {
"gte": 20000,
"lte": 30000
}
}
}
}'
但執行此當我收到以下異常:
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], all `shards failed; shardFailures {[eUQoAs5YTV-4zV0is80k-w][bank][0]: SearchParseException[[bank][0]: query[ConstantScore(*:*)],from[-1],size[-1]: Parse Failure [Failed to parse source [\n{\n \"query\": { \"match_all\": {} },\n \"sort\" : {\n balance : {\n \"range\" : {\n \"gte\": 20000,\n \"lte\": 30000\n }\n }\n }\n}]]]; nested: ElasticsearchIllegalArgumentException[sort option [range] not supported]; }`
,我沒有得到我在哪裏做的錯誤...
仍然得到SearchPhaseExecutionException ... – KayV
奇怪,它完美的作品在我的情況.. – christinabo
@KayV這個答案應該工作,錯誤SearchPhaseExecutionException是因爲你想放置的排序塊內的範圍,在這個答案的排序正確地移動,所以你不應該得到的錯誤了..你應該仔細檢查 –