Reputation: 2329
Following the official documentation about script fields i build a query something like this
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"
}
}
}
}
i get the distance scripted field on the hits but lost all _source fields from documents.
"hits": [
{
"_index": "abc",
"_type": "dfg",
"_id": "123456789",
"_score": 5.431662,
"fields": {
"distance": [
452.7564081099714
]
}
},
]
There is any way i can get scripted fields alongside _source fields of the document?
i look for something like:
"hits": [
{
"_index": "abc",
"_type": "dfg",
"_id": "123456789",
"_score": 5.431662,
"fields": {
"distance": [
452.7564081099714
]
"object": {
"property": 123,
"geo_point_property": xyz
}
}
},
]
PD: im using elastic 5.1
Upvotes: 1
Views: 1966
Reputation: 217504
Simply add _source: true
to your query
POST /abc/dfg/_search
{
"_source": true, <--- add this
"query": {
"bool": {
"must": [
...
Upvotes: 3