我正在尝试搜索具有相对于给定纬度/经度的多边形的文档。这是我的映射
{
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);
}
;
如果我在查询中指定索引/类型,我不会得到任何结果,如果我没有指定,那么无论我添加的过滤器如何,我都会获得所有文档。
答案 0 :(得分:1)
在您的查询中,您输入的类型有误,根据您的映射,它应该是land
而不是lands
:
var query = {
"index":"domains",
"type":"land",
"body": {
"query":{
"geo_shape": {
"location": {
"relation": "intersects",
"shape": {
"type": "point",
"coordinates":[-90.4244328,41.4794542]
}
}
}
}
}
};