在弹性搜索中使用脚本化字段时如何返回所有字段 [英] how to return all fields when using scripted fields in elastic search
本文介绍了在弹性搜索中使用脚本化字段时如何返回所有字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用弹性搜索,我试图将计算出的 distance
字段添加到地理搜索中.我只想在搜索文档中附加一个额外的计算字段,但是当我通过"script_fields"添加计算字段时,只会返回该字段.
Using elastic search I'm trying to add a calculated distance
field to a geo search. I just want to append an extra calculated field to the search document but when I add the calculated field via "script_fields", then only that field is returned.
我尝试添加通配符字段部分,但没有影响结果.
I tried adding a wildcard fields part, but it didn't affect the result.
如何使此查询返回添加了额外计算字段的完整文档
?
How to make this query return the complete documents
with the extra calculated field added?
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"
}
}
]
}
}
}
推荐答案
检索字段,您应该使用
Retrieving fields is not recommended, you should use source filtering instead.
所以,代替这个
"fields": [
".*"
],
使用此:
"_source": true
这篇关于在弹性搜索中使用脚本化字段时如何返回所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文