Is it possible to compute a field after a query?

Hello!

We have some objects. Each object has a 'score' and a 'name' (not unique).
We want to group the objects with the same name, get the sum of their score and then apply a simple formula to that sum.

I have managed to group the objects by name and get their sum using SQL:

SELECT name, sum(score) FROM bin
GROUP BY name

This produces the following JSON query when translated using _xpack/sql/translate:

{
    "size": 0,
    "_source": false,
    "stored_fields": "_none_",
    "aggregations": {
        "groupby": {
            "composite": {
                "size": 1000,
                "sources": [
                    {
                        "3096": {
                            "terms": {
                                "field": "name.keyword",
                                "missing_bucket": true,
                                "order": "asc"
                            }
                        }
                    }
                ]
            },
            "aggregations": {
                "3108": {
                    "sum": {
                        "field": "score"
                    }
                }
            }
        }
    }
}

These work and produce expected results.

Now, let's say I want not to return that 'sum' as it is, but return the sum/100 for each result.

Is this possible? If yes, then how?
I noticed know are scripts, but I spent hours trying to make it work using Painless scripts and other ways, but I haven't been able to get what I needed.

Thanks!

Bump

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.