I noticed that when using script_fields
it always return array of the values that should be returned. I wonder why is this happening and is it possible to just return a non-array data type like an object or bool?
Example to illustrate (taken from web)
GET sat/_search
{
"script_fields": {
"some_scores": {
"script": {
"lang": "painless",
"inline": "def scores = 0; scores = doc['AvgScrRead'].value + doc['AvgScrWrit'].value; return scores;" <--- we are returning a number here!
}
}
}
}
Result:
{
"_index": "sat",
"_type": "scores",
"_id": "AV3CYR8JFgEfgdUCQSON",
"_score": 1,
"_source": {
"cds": 1611760130062,
"rtype": "S",
"sname": "American High",
"dname": "Fremont Unified",
"cname": "Alameda",
"enroll12": 444,
"NumTstTakr": 298,
"AvgScrRead": 576,
"AvgScrMath": 610,
"AvgScrWrit": 576,
"NumGE1500": 229,
"PctGE1500": 76.85,
"year": 1516
},
"fields": {
"some_scores": [ <----- here it's an array
1152
]
}
}