我在理解用于形成 GeoDistance 查询的 DSL 语法时遇到了一些麻烦(获取距某个点一定距离内的所有条目);
目前,在我的 ES 索引"places" -> "shops"
中,id = 1
我有一个示例条目;
{
_index: "places",
_type: "shops",
_id: "1",
_version: 5,
found: true,
_source: {
location: {
lat: 50,
lon: 50
},
name: "coffee store",
posted: "2014-09-12T08:53:01.673Z"
}
}
然后,使用 Elastic4s DSL,我正在构建一个搜索查询;
val nearbyStoresFuture:Future[SearchResponse] = client execute {
search in "places" -> "shops" filter {
geoDistance("location") point(lat, lon) distance(distance)
}
}
nearbyStoresFuture onComplete {
case Success(s) => {
s
client.close
}
case Failure(t) => {
t
client.close
}
}
在这种情况下:
lat: Double = 50.0
lon: Double = 50.0
distance: String = "50km"
所以无论如何,如果查询是正确的,这应该给我包含 ES 中的条目的结果,因为它与条目位于同一点,因此在 50 公里的距离内。
查询成功但结果为空。
编辑:这是映射的样子;
ES.execute {
create index "places" mappings(
"shops" as (
"location" typed GeoPointType,
"name" typed StringType,
"posted" typed DateType
)
)
}
这有什么问题?