ElasticSearch version is 2.3.4
如何查询geo_distance_query和script_query组合?ElasticSearch脚本查询和地理距离查询
我有一个索引,它有很多的商店信息,有位置和距离的字段。 给定一个geo_point,该索引根据基于geo_distance_query的查询顶部这一点来存储所有的距离,并且计算出的距离应该小于当前存储在距离字段中的值。
我觉得script_query和geo_distance_query的组合,不知道该怎么实现。
试试下面的代码:
query: {
bool: {
must: [
{
script: {
script: {
inline: "doc['location'].arcDistance(" + _.lat + "," + _.lon + ") < doc['distance'].value"
, lang: "painless"
}
}
}
]
}
}
结果Elasticsearch错误:
[illegal_argument_exception] script_lang not supported [painless]
是否有人遇到并解决了这个问题,用什么方法来实现查询?
变化码:
{
bool: {
must: [
{
script: {
script: {
inline: "doc['location'].arcDistance(" + _.lat + "," + _.lon + ") < doc['distance'].value"
, lang: "groovy"
}
}
}
]
}
}
也错误:
message: '[script_exception] failed to run inline script [doc[\'location\'].arcDistance(31.89484,120.287825) < doc[\'distance\'].value] using lang [groovy]',
细节图像:
{
"error": {
"root_cause": [{
"type": "script_exception",
"reason": "failed to run inline script [doc[\'location\'].arcDistance(31.89484,120.287825) < 3000] using lang [groovy]"
}],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query_fetch",
"grouped": true,
"failed_shards": [{
"shard": 0,
"index": "business_stores_v1",
"node": "Z_65eOYXT6u8aDf7mp2ZRg",
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [doc[\'location\'].arcDistance(31.89484,120.287825) < 3000] using lang [groovy]",
"caused_by": {"type": "null_pointer_exception", "reason": null}
}
}]
}, "status": 500
}
的'painless'脚本语言已经在ES 5中引入了。这个错误意味着你正在运行ES 2.x,并且正在阅读ES 5的文档。如果你正在运行ES 2.x,那么使用'groovy'而不是'无痛' – Val
@Val已经更新。也错误。 我不认为他支持这种查询与动态比较的方式进行比较。 – sky91
你现在得到什么错误?肯定是一个不同的。 '_.lat'和'_.lon'从哪里来? – Val