我在nodejs app中使用elasticsearch模块,以便按geo_points查找文档。
client.search({
index: 'myindex',
type: 'mytype',
body: {
filtered : {
query : {
match_all : {}
},
filter : {
geo_distance : {
distance : "200km",
coordiates : {
lat : 40,
lon : -70
}
}
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
console.log(hits, "items");
}).catch(function (error) {
console.log("Error on geo_distance");
});
但我总是遇到搜索解析错误。
有人有想法吗?
THX
答案 0 :(得分:2)
最后,我找到了正确的语法/参数:
client.search({
index: 'myindex',
type: 'mytype',
body: {
from: from,
size: size,
query: {
filtered: {
filter: {
geo_distance: {
distance: '100000km',
coordiates: {
lat: 0.0,
lon: 0.0
}
}
}
}
}
}
}).then(function (resp) {
var hits = resp.hits.hits;
console.log(hits.length, "items around");
}).catch(function (error) {
console.log("Error on geo_distance (coordiates)");
});
Thx Jhilden为你提供帮助。