gpt4 book ai didi

elasticsearch - 从Elastic Search中的结果获取每个坐标的距离

转载 作者:行者123 更新时间:2023-12-03 02:10:50 25 4
gpt4 key购买 nike

我需要过滤最接近给定坐标的记录。从下面的查询中删除 script_fields 将起作用(给出结果)。
需要获取每个匹配结果的距离。

GET story/_search
{
"_source": [
"title.english", "location"
],
"query": {
"bool": {
"filter": [
{
"geo_distance": {
"distance": "1000km",
"location": {
"lat": 57.3079700,
"lon": 123.4977090
}
}
}
]
}
},
"script_fields": {
"distance": {
"script": "doc['location'].distanceInKm(57.3079700, 123.4977090)"
}
}
}
以下是错误
"failures" : [
{
"shard" : 1,
"index" : "story",
"node" : "asdf-asdf",
"reason" : {
"type" : "script_exception",
"reason" : "runtime error",
"script_stack" : [
"doc['location'].distanceInKm(57.3079700, 123.4977090)",
" ^---- HERE"
],
"script" : "doc['location'].distanceInKm(57.3079700, 123.4977090)",
"lang" : "painless",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "dynamic method [org.elasticsearch.index.fielddata.ScriptDocValues.GeoPoints, distanceInKm/2] not found"
}
}
}
]
},

最佳答案

正如@Sharath指出的那样,不建议使用distanceInKm。这些天,您可以使用arcDistance并通过除以1000将值转换为km。

GET my-index-000001/_search
{
...
"script_fields": {
"distance": {
"script": "doc['location'].arcDistance(57.3079700, 123.4977090) / 1000"
}
}
}
这是 currently supported geo methods的列表,这是 arcDstance source

关于elasticsearch - 从Elastic Search中的结果获取每个坐标的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64737926/

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