使用弹性搜索我尝试将计算出的distance
字段添加到地理位置搜索中。我只想在搜索文档中附加一个额外的计算字段,但是当我通过" script_fields"添加计算字段时,只返回该字段。
我尝试添加通配符字段部分,但它并没有影响结果。
如何使此查询返回complete documents
并添加了额外的计算字段?
GET /ocsm_test/inventory/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "2km",
"address.geo.location": [],
"loc.address.geo.location": [
151.2165507,
-33.8732887
]
}
}
}
},
"aggs": {
"partNumber": {
"terms": {
"field": "partNumber",
"order": {
"_term": "asc"
}
}
},
"location": {
"terms": {
"field": "loc.identifier",
"order": {
"_term": "asc"
}
}
}
},
"script_fields": {
"distance": {
"params": {
"lat": -33.8732887,
"lon": 151.2165507
},
"script": "doc['loc.address.geo.location'].distanceInKm(lat,lon)"
}
},
"fields": [
".*"
],
"post_filter": {
"bool": {
"must": [
{
"term": {
"partNumber": "p-0099393-3"
}
}
]
}
}
}
答案 0 :(得分:4)