【问题标题】:ES giving error when sorting by distanceES按距离排序时出错
【发布时间】:2016-12-29 11:57:37
【问题描述】:

我正在尝试按距离对搜索结果进行排序。但是,当我尝试时,出现以下错误:

{
   "error": {
      "root_cause": [
         {
            "type": "illegal_argument_exception",
            "reason": "sort option [location] not supported"
         }
      ],
      "type": "search_phase_execution_exception",
      "reason": "all shards failed",
      "phase": "query",
      "grouped": true,
      "failed_shards": [
         {
            "shard": 0,
            "index": "roeselaredev",
            "node": "2UYlfd7sTd6qlJWgdK2wzQ",
            "reason": {
               "type": "illegal_argument_exception",
               "reason": "sort option [location] not supported"
            }
         }
      ]
   },
   "status": 400
}

我发送的查询如下所示:

GET _search
{
    "query": {
        "match_all": [] 
    },
    "sort": [

        {
            "geo_distance": {
                "location": {
                    "lat": 50.9436034,
                    "long": 3.1242917
                },
                "order":"asc",
                "unit":"km",
                "distance_type":"plane"
            }
        },
        {
            "_score": {
                "order":"desc"   
            }        
        }
    ]
}

据我所知,我严格按照文档中的说明进行操作。我没有收到格式错误的查询结果。我只是得到一个不支持的按距离排序选项的结果。关于我做错了什么的任何想法?

【问题讨论】:

  • 如何映射geo_distance
  • geo_distance 是过滤器的名称,它没有被映射。位置映射如下:location: { type: geo_point, property_path: esGetLocation } esGetLocation 方法只返回一个包含 lat 和 long 连接的字符串(用逗号分隔)

标签: sorting elasticsearch geo foselasticabundle


【解决方案1】:

查询 dsl 无效,OP 几乎正确 :) 但缺少下划线。

虽然按距离排序,但它是 _geo_distance 而不是 geo_distance

例子:

GET _search
{
    "query": {
        "match_all": [] 
    },
    "sort": [

        {
            "_geo_distance": {
                "location": {
                    "lat": 50.9436034,
                    "long": 3.1242917
                },
                "order":"asc",
                "unit":"km",
                "distance_type":"plane"
            }
        },
        {
            "_score": {
                "order":"desc"   
            }        
        }
    ]
}

【讨论】:

  • gah :p 非常感谢!
猜你喜欢
  • 2016-01-02
  • 1970-01-01
  • 2013-11-11
  • 2015-10-07
  • 2018-02-02
  • 2015-04-27
  • 1970-01-01
  • 2017-07-29
  • 2013-12-05
相关资源
最近更新 更多