关于脚本字段the official documentation后,我构建了类似这样的查询
GET /abc/dfg/_search
{
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{
"range": {
"object.property": {
"gte": 6.05,
"lte": 18.15,
"include_lower": false,
"include_upper": false
}
}
}
]
}
}
],
"filter": [
{
"bool": {
"must": [
{
"geo_distance": {
"distance": "25mi",
"object.geo_point_property": {
"lat": 40.753333,
"lon": -73.976667
}
}
}
]
}
}
]
}
},
"script_fields": {
"distance": {
"script": {
"inline": "doc['object.geo_point_property'].planeDistanceWithDefault(params.lat,params.lon, 0)",
"params": {
"lat": 40.753333,
"lon": -73.976667
},
"lang": "painless"
}
}
}
}
我在点击中获得了距离脚本字段,但丢失了文档中的所有_source字段。
"hits": [
{
"_index": "abc",
"_type": "dfg",
"_id": "123456789",
"_score": 5.431662,
"fields": {
"distance": [
452.7564081099714
]
}
},
]
有什么方法可以在文档的_source字段旁边获取脚本字段?
我寻找类似的东西:
"hits": [
{
"_index": "abc",
"_type": "dfg",
"_id": "123456789",
"_score": 5.431662,
"fields": {
"distance": [
452.7564081099714
]
"object": {
"property": 123,
"geo_point_property": xyz
}
}
},
]
PD:即时使用弹性5.1
答案 0 :(得分:2)
只需在查询中添加_source: true
POST /abc/dfg/_search
{
"_source": true, <--- add this
"query": {
"bool": {
"must": [
...