我与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是因为你想放置的排序块内的范围,在这个答案的排序正确地移动,所以你不应该得到的错误了..你应该仔细检查 –