gpt4 book ai didi

elasticsearch - Elasticsearch无法使用lang groovy运行内联脚本[doc…]

转载 作者:行者123 更新时间:2023-12-02 22:44:39 25 4
gpt4 key购买 nike

尝试匹配索引中的所有索引并显示给定geo_point与查询结果之间的距离时出现此错误,我使用DrTech's答案来显示脚本距离:

这是我的DSL查询:

{
"query": {
"match_all": {}
},
"script_fields": {
"distance": {
"lang": "groovy",
"params": {
"lat": 2.27,
"lon": 50.3
},
"script": "doc['geo_coordinates'].distanceInKm(lat,lon)"
}
}
}

查询响应:
{
"took": 50,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 4,
"failed": 1,
"failures": [
{
"shard": 0,
"index": "users",
"node": "pa76fjdWQl2YAHmgCT4oKw",
"reason": {
"type": "script_exception",
"reason": "failed to run inline script [doc['geo_coordinates'].distanceInKm(lat,lon)] using lang [groovy]",
"caused_by": {
"type": "null_pointer_exception",
"reason": null
}
}
}
]
},
"hits": {
"total": 184,
"max_score": 1,
"hits": []
}

我在映射中有这个:
  "geo_coordinates" : {
"type" : "geo_point",
"lat_lon" : true
},

所以我不明白为什么我得到了一个空指针! .....

最佳答案

可能是因为其中一个文档在geo_coordinates字段中没有任何值。因此,您需要在脚本中考虑这种情况。

尝试以下方法:

{
"query": {
"match_all": {}
},
"script_fields": {
"distance": {
"lang": "groovy",
"params": {
"lat": 2.27,
"lon": 50.3
},
"script": "doc['geo_coordinates'] ? doc['geo_coordinates'].distanceInKm(lat,lon) : 0"
}
}
}

关于elasticsearch - Elasticsearch无法使用lang groovy运行内联脚本[doc…],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37836369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com