# Bucket Script in Composite Aggregation using Java client 8.8.2

**URL:** <https://discuss.elastic.co/t/bucket-script-in-composite-aggregation-using-java-client-8-8-2/340569>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [August 10, 2023, 2:08pm UTC](https://discuss.elastic.co/t/bucket-script-in-composite-aggregation-using-java-client-8-8-2/340569 "2023-08-10T14:08:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tcpeiris](https://avatars.discourse-cdn.com/v4/letter/t/54ee81/32.png) [@tcpeiris](https://discuss.elastic.co/u/tcpeiris)\
**Post date:** [August 10, 2023, 2:08pm UTC](https://discuss.elastic.co/t/bucket-script-in-composite-aggregation-using-java-client-8-8-2/340569/1 "2023-08-10T14:08:39Z")

</div>

Java method should be written for the following ES query and I'm getting an error on script() function.

```auto
"AVERAGE": {
                    "bucket_script": {
                        "buckets_path": {
                            "SUM_TWO": "2ycc",
                            "SUM_RESEARCH": "roc"
                        },
                        "script": "params.SUM_TWO / params.SUM_RESEARCH"
                    }
                }

```

```auto
Map<String, String> dictionary = new HashMap<>();
        dictionary.put(field1, field2);
        dictionary.put(field1, field2);

        String scriptCode = "params.SUM_TWO / params.SUM_RESEARCH";

        return new Aggregation.Builder()
               .bucketScript(new BucketScriptAggregation.Builder().bucketsPath(new BucketsPath.Builder().dict(dictionary).build()).script(t -> t.inline(scriptCode))).build();

```

---

<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:** [September 7, 2023, 2:09pm UTC](https://discuss.elastic.co/t/bucket-script-in-composite-aggregation-using-java-client-8-8-2/340569/2 "2023-09-07T14:09:10Z")

</div>

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