2017-06-20 58 views
0

映射address属性:nameidtypelocation。 搜索映射:elasticsearch GEO的搜索顺序由近至远

{ 
    "address": { 
    "properties": { 
     "id": { 
     "type": "long" 
     }, 
     "type": { 
     "type": "long" 
     }, 
     "name": { 
     "type": "string" 
     }, 
     "location": { 
     "type": "geo_point" 
     } 
    } 
    } 
} 

搜索CMD(滤波器address.type = 1distance = 100km):

XGET /_search 
{ 
    "query": { 
    "filtered": { 
     "query": { 
     "match": { 
      "type": 1 
     } 
     }, 
     "filter": { 
     "geo_distance": { 
      "distance": "100km", 
      "location": { 
      "lat": 24.46667, 
      "lon": 118.1 
      } 
     } 
     } 
    } 
    } 
} 

我想搜索地址匹配type = 1和地理distance = 100km;我想得到的结果是order by distance ASC。如何解决这个问题?

回答

1

由于您基于距离进行排序,因此我在布尔过滤器中移动了匹配查询。

这应该工作

{ 
    "query": { 
     "bool": { 
      "must": [{ 
        "geo_distance": { 
         "distance": "1000000km", 
         "location": { 
          "lat": 24.46667, 
          "lon": 118.1 
         } 
        } 
       }, 
       { 
        "term": { 
         "type": { 
          "value": 1 
         } 
        } 
       } 
      ] 
     } 
    }, 
    "sort": { 
     "_geo_distance": { 
      "location": "24.46667,118.1", 
      "order": "asc" 
     } 
    } 
} 
+0

是的,它的工作原理。谢谢! –