在 geo_shape 查询 elasticsearch 中查找多边形

Finding polygons in geo_shape query elasticsearch

我正在尝试搜索多边形相交给定 lat/lon 的文档。这是我的映射

{
    index:"domains",
    type:"land",
    body:{
        properties:{
                landId:{
                    type:"integer"
                },
                name:{
                    type:"string"
                },
                location:{
                    type:"geo_shape"
                }
        }
    }
}

这是我为文档编制索引的方式

{
    landId:1,
    name:"My Test location ",
    location:{
        type:"polygon",
        coordinates: [[
            [-90.4321575,41.4854342],
            [-90.4318142,41.469615],
            [-90.4138756,41.4697436],
            [-90.4139614,41.4855628],
            [-90.4321575,41.4854342]
        ]]
    }

}

这是我的查询

var query = {
   "index":"domains",
   "type":"lands",
   "match_all":{},
    "geo_shape": {
    "location": {
     "relation": "intersects",
     "shape": {
        "type":   "point",
         "coordinates":[-90.4244328,41.4794542]
        }
      } 
    }
}

return esClient.search(query).then(function(resp){
  console.log("**** GOT RESPONSE from Search ****")
  console.log(resp.hits);
    return resp.hits.hits[0]._source;

}),function (err) {
    console.trace(err.message);
}
  ;

如果我在查询中指定 index/type,我不会得到任何结果,如果我没有指定,那么我会得到所有文档,而不管我添加的过滤器是什么。

在您的查询中,您的类型有误,根据您的映射,它应该是 land 而不是 lands

var query = {
   "index":"domains",
   "type":"land",
   "body": {
     "query":{
       "geo_shape": {
         "location": {
          "relation": "intersects",
          "shape": {
            "type":   "point",
            "coordinates":[-90.4244328,41.4794542]
          }
         } 
       }
     }
   }
};