将每个匹配的记录值传递到 Elasticsearch 中的过滤器
对于 geo_distance
查询,我使用距离常量值。我需要让它变得动态。所以我想将上面匹配的记录半径值传递给距离。
代码如下:
let searchRadius = '12KM'
query: {
bool: {
must: {
match: {
companyName: {
query: req.text
}
}
},
filter: {
geo_distance: {
distance: searchRadius,//here I want to pass doc['radius']
location: {
lat: parseFloat(req.lat),
lon: parseFloat(req.lon)
}
}
},
}
}
对于每条记录,我都有不同的半径 > 价值。我想传递 doc['radius'] 而不是常量 searchRadius
值。
我可以点击两个查询然后迭代这些值,但这不是最佳的。谁能建议我如何将每个记录值传递给 geo_distance 过滤器?
For geo_distance
query I'm using a constant value for distance. I need to make it dynamic. So I want to pass the above matched record radius value to distance.
Here's the code:
let searchRadius = '12KM'
query: {
bool: {
must: {
match: {
companyName: {
query: req.text
}
}
},
filter: {
geo_distance: {
distance: searchRadius,//here I want to pass doc['radius']
location: {
lat: parseFloat(req.lat),
lon: parseFloat(req.lon)
}
}
},
}
}
For each record, I have a different radius value. I want to pass doc['radius']
instead of constant searchRadius
value.
I can hit two queries then iterate the values but it's not optimal. Can anyone suggest how can I pass each record value to geo_distance filter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经从这个答案中解决了。
下面是使用脚本查询的代码
,来自更多详细信息:
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-script-query.html
I have resolved from this answer.
Heres the code
Using script Query, from more details:
https://www.elastic.co/guide/en/elasticsearch/reference/6.1/query-dsl-script-query.html