我编写了下面的查询,先按最近的用户排序,然后再按剩余的用户排序,但是当我在kibana上运行这个查询时,它会抛出一个异常,而我不知道错误是什么?
查询
{
"query": {
"bool": {
"must": [
{
"term": {
"type": "user"
}
}
],
"filter": {
"geo_distance": {
"distance": "1000km",
"location": {
"lat": 24.71532,
"lon": 46.66479
}
}
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 24.71532,
"lon": 46.66479
},
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
]
}
}
Exception
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 21,
"col": 5
}
],
"type": "parsing_exception",
"reason": "[bool] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
"line": 21,
"col": 5
},
"status": 400
}
我在弹性搜索官方网站上找到了这个代码。当我在没有排序过滤器的情况下运行这个查询时,这个查询可以工作,但是当我添加排序过滤器时,你会得到一个异常。
请指导我解决这个查询问题。
发布于 2018-08-31 07:01:20
sort
部分需要与query
部分处于相同的级别,而不是在其内部:
{
"sort": [
{
"_geo_distance": {
"location": {
"lat": 24.71532,
"lon": 46.66479
},
"order": "asc",
"unit": "km",
"distance_type": "plane"
}
}
],
"query": {
"bool": {
"must": [
{
"term": {
"type": "user"
}
}
],
"filter": {
"geo_distance": {
"distance": "1000km",
"location": {
"lat": 24.71532,
"lon": 46.66479
}
}
}
}
}
}
https://stackoverflow.com/questions/52118131
复制