【发布时间】:2016-12-21 21:07:56
【问题描述】:
按照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
【问题讨论】:
-
如果您在查询的顶层添加
"_source": true会发生什么? -
优秀的@Val 做到了,谢谢
标签: elasticsearch