【问题标题】:elasticsearch geo bounding box not returning resultselasticsearch地理边界框不返回结果
【发布时间】:2017-04-16 14:02:49
【问题描述】:

我正在尝试使用弹性搜索的地理边界框功能在我选择的框中返回结果。我从谷歌地图上得到了边界坐标,它是东北和西南格式的。

这是传递给 elasticsearch php 客户端的参数转储示例(为了便于阅读,已转换为 JSON):

{
   "index":"MyIndex",
   "body":{
      "query":{
         "bool":{
            "must":{
               "match_all":{

               }
            },
            "filter":{
               "geo_bounding_box":{
                  "location":{
                     "top_right":{
                        "lat":53.2323104,
                        "lon":6.704821
                     },
                     "bottom_left":{
                        "lat":52.3136724,
                        "lon":4.311799
                     }
                  }
               }
            }
         }
      }
   }
}

这里有一些在 ES 中的示例结果,当我进行正常的简单搜索(无地理/边界框)时会返回:

[
   {
      "object_id":14396,
      "object_type":"POI",
      "location":{
         "lat":53.05194,
         "lon":5.38417
      }
   },
   {
      "object_id":24046,
      "object_type":"POI",
      "location":{
         "lat":52.52711,
         "lon":5.06319
      }
   },
   {
      "object_id":24680,
      "object_type":"POI",
      "location":{
         "lat":52.72525,
         "lon":4.96201
      }
   }
]

我相信这些都应该由边界框搜索返回,我在这里遗漏了什么?

编辑:下面包含映射

{
   "MyIndex":{
      "mappings":{
         "pois":{
            "properties":{
               "object_id":{
                  "type":"string"
               },
               "object_type":{
                  "type":"string"
               },
               "location":{
                  "type":"geo_point"
               },
            }
         },
      }
   }
}

编辑 2:在 ES 中使用数据的原始响应:

{
   "_index":"MyIndex",
   "_type":"pois",
   "_id":"14916",
   "_score":1,
   "_source":{
      "object_id":"14916",
      "object_type":"POI",
      "location":{
         "lat":53.13915,
         "lon":6.19422
      }
   }
}

【问题讨论】:

  • 你能展示一下你从curl -XGET localhost:9200/MyIndex/_mapping得到什么吗?
  • @val 用映射更新了我的答案。请注意,示例结果不是来自 ES 的原始响应。这是我从我的 API 得到的响应。我现在还添加了原始 ES 响应。

标签: php elasticsearch geolocation elasticsearch-5


【解决方案1】:

top_leftbottom_right 值传递不正确。尝试设置如下值:

location :{
    "top_right":{
        "lat":53.2323104,
        "lon":4.311799
        },
    "bottom_left":{
        "lat":52.3136724,
        "lon":6.704821
        }
}

【讨论】:

  • 您刚刚复制粘贴了示例转储(为了便于阅读而转换为 JSON)。你没有提供答案。你的“答案”不是答案。
  • @AksenP 我在这里要强调的是 top_rightbottom_left lat lon 值传递不正确。我已更正它们并粘贴了来自 kibana 开发工具的请求数据。让我用解释更新我的答案。感谢您指出它。感激不尽!
  • "lon":6.704821 vs. "lon":4.311799 - 无用的修正,因为这些值是动态的。您没有按原样得到问题。
猜你喜欢
  • 2014-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-01
  • 1970-01-01
相关资源
最近更新 更多