# How get sum for example with integer fields of each doc

**URL:** https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747
**Category:** Elasticsearch
**Created:** [September 9, 2021, 7:44am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747 "2021-09-09T07:44:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Grigor\_Martirosyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grigor_martirosyan/32/93945_2.png) [@Grigor\_Martirosyan](https://discuss.elastic.co/u/Grigor_Martirosyan)
#### Post date: [September 9, 2021, 7:44am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/1 "2021-09-09T07:44:29Z")

</div>

I use elastic with spring boot ,and have integer fields in my doc and now I need to do some calculation with those fields for each doc ,is that possible??

this is some try

```auto
Script script = new Script("{\n" +
            " \"script_fields\": {\n" +
            " \"my_doubled_field\": {\n" +
            " \"script\": {\n" +
            " \"lang\": \"expression\",\n" +
            " \"source\": \"doc['salary'] * multiplier\",\n" +
            " \"params\": {\n" +
            " \"multiplier\": 2\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            " }\n" +
            "}");

    QueryBuilder queryBuilder1= QueryBuilders
            .scriptQuery(script);
    Query query= new NativeSearchQueryBuilder()
            .withQuery(queryBuilder1)
            .build();

    SearchHits<Stories>
            searchHits = elasticsearchOperations.search(query, Stories.class
            , IndexCoordinates.of("products"));

```

but doesn't work

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 9, 2021, 9:14am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/2 "2021-09-09T09:14:11Z")

</div>

Are you asking how to do this with Enterprise Search, or Elasticsearch?

---

<div class="post-metadata">

### Author: ![Grigor\_Martirosyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grigor_martirosyan/32/93945_2.png) [@Grigor\_Martirosyan](https://discuss.elastic.co/u/Grigor_Martirosyan)
#### Post date: [September 9, 2021, 10:35am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/3 "2021-09-09T10:35:07Z")

</div>

I'm asking how to do this in spring boot

---

<div class="post-metadata">

### Author: ![Grigor\_Martirosyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grigor_martirosyan/32/93945_2.png) [@Grigor\_Martirosyan](https://discuss.elastic.co/u/Grigor_Martirosyan)
#### Post date: [September 9, 2021, 10:37am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/4 "2021-09-09T10:37:54Z")

</div>

hi @warkolm I integrated elastic with spring boot and now need to do that is that possible?

---

<div class="post-metadata">

### Author: ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)
#### Post date: [September 9, 2021, 10:39am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/5 "2021-09-09T10:39:14Z")

</div>

I am not sure, but you asked in Workplace Search, which is not the right category. I will move this.

---

<div class="post-metadata">

### Author: ![Grigor\_Martirosyan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/grigor_martirosyan/32/93945_2.png) [@Grigor\_Martirosyan](https://discuss.elastic.co/u/Grigor_Martirosyan)
#### Post date: [September 9, 2021, 10:39am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/6 "2021-09-09T10:39:33Z")

</div>

okay @warkolm thanks

---

<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: [October 7, 2021, 10:39am UTC](https://discuss.elastic.co/t/how-get-sum-for-example-with-integer-fields-of-each-doc/283747/7 "2021-10-07T10:39:50Z")

</div>

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