时才这样做
在elasticsearch中,我想用 geo_distance filter。
查询多个索引。问题是一个索引具有geo_point映射,另一个索引没有geo_point映射。
如果我使用纬度和经度查询,我只会获得具有GEO_POINT映射的索引的结果。对于其他索引,我得到的未能找到geo_point字段 exception。
如何从两个指数中获得结果?
以下是我的查询。
{
"query":{
"filtered":{
"query":{
"bool":{
"should":{
"match_all":{
}
}
}
},
"filter":{
"bool":{
"should":[
{
"bool":{
"must":[
{
"geo_distance":{
"distance":"50km",
"location":{
"lat":22.5705741,
"lon":88.4355427
}
}
}
]
}
}
]
}
}
}
},
"sort":[
{
"_geo_distance":{
"location":{
"lat":22.5705741,
"lon":88.4355427
},
"order":"asc",
"unit":"km"
}
}
],
"size":30,
"from":0
}
我正在使用Elasticsearch Verion 0.90.12
请参阅您的最后评论,我认为您可以尝试以下方式:
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"bool": {
"must": [
{
"term": {
"_index": "index_name_with_geo_point"
},
"geo_distance": {
"from": 100,
"to": 200,
"distance_unit": "km",
"location": {
"lat": 40.73,
"lon": -74.1
}
}
}
]
}
},
{
"term": {
"_index": "Index_name_without_geo_point"
}
}
]
}
}
}
}
}
现在或
- ducument必须来自地理点和地理范围的索引
- 该文档不是带有地理点的索引。
ofCorse您可以将应查询的第二个元素扩展到bool : {must : {terms : {}}}
,因为第一个元素是 ,但是只有在必要的