# Is it possible to compute a field after a query?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-compute-a-field-after-a-query/190047>\
**Category:** Elasticsearch\
**Created:** [July 11, 2019, 2:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-compute-a-field-after-a-query/190047 "2019-07-11T14:52:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Irimia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_irimia/32/48742_2.png) [@David\_Irimia](https://discuss.elastic.co/u/David_Irimia)\
**Post date:** [July 11, 2019, 2:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-compute-a-field-after-a-query/190047/1 "2019-07-11T14:52:12Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![David\_Irimia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/david_irimia/32/48742_2.png) [@David\_Irimia](https://discuss.elastic.co/u/David_Irimia)\
**Post date:** [July 15, 2019, 8:34am UTC](https://discuss.elastic.co/t/is-it-possible-to-compute-a-field-after-a-query/190047/2 "2019-07-15T08:34:49Z")

</div>

Bump

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 12, 2019, 8:34am UTC](https://discuss.elastic.co/t/is-it-possible-to-compute-a-field-after-a-query/190047/3 "2019-08-12T08:34:54Z")

</div>

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