ElasticSearch version is 2.3.4
如何查询geo_distance_query和script_query组合?
我有一个索引,它有很多商店信息,还有位置和距离字段。 给定一个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
}
答案 0 :(得分:0)
您获得的错误,即null_pointer_exception
,是因为business_stores_v1
索引中的某个文档有一个空location
字段,因此公式失败
doc['location'].arcDistance(...)
^
|
null_pointer_exception here