【发布时间】:2016-04-21 21:25:30
【问题描述】:
映射为:
"mappings": {
"gyms": {
"properties": {
"location": {
"type": "geo_point"
},
"name": {
"type": "string"
}
}
}
}
我正在尝试检索距给定纬度、经度 10 公里处的所有健身房。 我正在使用这个查询:
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": 10,
"distance_unit": "km",
"location": {
"lat": 41.3819756,
"lon": 2.17
}
}
}
}
}
}
但是出了点问题,因为我在指定的纬度附近有一些健身房,并且弹性搜索响应没有文档。 会发生什么?
更新 查询:
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "10km",
"location": {
"lat": 41.3819756,
"lon": 2.17
}
}
}
}
}
按预期工作!
作为应该出现的文档示例:
{
"_index": "g4l",
"_type": "gyms",
"_score": 1,
"_source": {
"gymName": "sds",
"location": {
"lat": 41.3994375,
"lon": 2.16152349999993
}
}
},
{
"_index": "g4l",
"_type": "gyms",
"_score": 1,
"_source": {
"gymName": "sdf",
"location": {
"lat": 41.4040134,
"lon": 2.201350400000024
}
}
}
【问题讨论】:
-
你能举一个你认为在远处的有索引的健身房的例子吗(不要凭记忆,而是直接从索引中复制)?
-
为我工作。这是什么版本的ES?
-
1.6.0 似乎使用米而不是公里进行搜索