ElasticSearch8.6 _geo_distance排序引发错误

pxyaymoc  于 2023-01-25  发布在  ElasticSearch
关注(0)|答案(1)|浏览(161)

今天我想在我的查询中添加基于地理的排序。2我使用弹性(8. 6)企业搜索/应用程序搜索。
我的请求正文:

{
  "query": "",
  "filters": {
    "location": {
      "center": "51.071646,6.3195429",
      "distance": 500,
      "unit": "km"
    }
  },
  "sort": [
    {
      "_geo_distance": {
        "location": [
          51.071646,
          6.3195429
        ],
        "order": "asc",
        "mode": "min",
        "distance_type": "plane",
        "ignore_unmapped": true
      }
    }
  ],
  "page": {
    "size": 20,
    "current": 1
  }
}

...我得到以下响应正文:

{
  "errors": [
    "Sort contains invalid field: _geo_distance"
  ]
}

我的文档字段 * location * 在模式中设置为 * geolocation
有人能给我一点提示吗,我在这里根本做错了什么?
如果没有'
sort *'属性,搜索将按预期执行,但我希望在响应中也包含与所请求位置相关的距离。
多谢了!

2w3rbyxf

2w3rbyxf1#

对于那些面临类似情况的人,我应用了错误的语法!因为我在 ElasticAppSearch 中,它必须是

{
  "query": "",
  "filters": {
    "location": {
      "center": "51.071646,6.3195429",
      "distance": 500,
      "unit": "km"
    }
  },
  "sort": [
    {
      "location": {
        "center": "51.071646,6.3195429",
        "order": "asc"
      }
    }
  ],
  "page": {
    "size": 20,
    "current": 1
  }
}

相关问题