gpt4 book ai didi

php - Elasticsearch距离查询异常抛出

转载 作者:行者123 更新时间:2023-12-02 23:18:30 24 4
gpt4 key购买 nike

我编写了以下查询,首先按最近的用户排序,然后按其余用户排序,但是当我在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
}

我在 flex 搜索官方网站上找到了此代码。当我在不使用排序过滤器的情况下运行此查询时,此查询有效,但是当我添加排序过滤器U时会出现异常。

请指导我解决此查询问题。

最佳答案

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
}
}
}
}
}
}

关于php - Elasticsearch距离查询异常抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52118131/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com