我需要返回Elasticsearch 数组中每个文档的多个地理点的距离。截至目前,我的结果只返回为数组计算的一个距离。
我从以下 StackOverflow 问题的代码开始: Return distance in elasticsearch results?
我的 elasticsearch 查询正文包含以下内容:
{
"stored_fields" : [ "_source" ],
"script_fields" : {
"distance" : {
"script" : {
"inline": "doc['locations.facility.address.coordinates'].arcDistance(params.lat,params.lon) * 0.001",
"lang": "painless",
"params": {
"lat": 2.27,
"lon": 50.3
}
}
}
}
}
而且,我的 Elasticsearch 源文档在返回时与此类似。(请注意,位置是一个数组。)
"locations": [
{
"facility": {
"address": {
"country_code": "US",
"city": "San Diego",
"coordinates": {
"lon": -117.165,
"lat": 32.8408
},
"country_name": "United States",
"state_province": "California",
"postal_code": "92123"
}
}
},
{
"facility": {
"address": {
"country_code": "US",
"city": "Tampa",
"coordinates": {
"lon": -82.505,
"lat": 28.0831
},
"country_name": "United States",
"state_province": "Florida",
"postal_code": "33613"
}
}
}
]
目前,我的结果返回类似于以下内容:
"fields": {
"distance": [
13952.518249603361
]
}
但是在距离数组中,我需要为“位置”中的每个条目返回一个值。