elasticsearch,Php,Laravel,elasticsearch" /> elasticsearch,Php,Laravel,elasticsearch" />

Php Elasticsearch距离查询异常引发

Php Elasticsearch距离查询异常引发,php,laravel,elasticsearch,Php,Laravel,elasticsearch,我编写了以下查询,首先按最近的用户排序,然后按剩余用户排序,但当我在kibana上运行此查询时,它抛出了一个异常,我不知道错误是什么 查询 { "query": { "bool": { "must": [ { "term": { "type": "user" } } ], "filter": { "geo_distance": {

我编写了以下查询,首先按最近的用户排序,然后按剩余用户排序,但当我在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
}
我在elastic search官方网站上找到了这个代码。当我在没有排序过滤器的情况下运行此查询时,此查询有效,但当我添加排序过滤器时,会出现异常


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

排序部分需要与查询部分处于同一级别,而不是在其内部:

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

运气好吗?