# JSON with script and aggregation Query to Java REST High or Low Level Client

**URL:** <https://discuss.elastic.co/t/json-with-script-and-aggregation-query-to-java-rest-high-or-low-level-client/204477>\
**Category:** Elasticsearch\
**Created:** [October 21, 2019, 1:08pm UTC](https://discuss.elastic.co/t/json-with-script-and-aggregation-query-to-java-rest-high-or-low-level-client/204477 "2019-10-21T13:08:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakotomandimby](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rakotomandimby/32/48493_2.png) [@rakotomandimby](https://discuss.elastic.co/u/rakotomandimby)\
**Post date:** [October 21, 2019, 1:08pm UTC](https://discuss.elastic.co/t/json-with-script-and-aggregation-query-to-java-rest-high-or-low-level-client/204477/1 "2019-10-21T13:08:40Z")

</div>

Hi all,  
I'm querying ES 7.3 from the Java REST High Level Client.  
For "simple" queries, I have always been able to transcript them to Java, but this time, I face the problem.  
This is the JSON query

```
{
    "query": {
        "bool": {
            "filter": {
                "script": {
                    "script": {
                        "source": "(doc['mois'].value.getYear()==2019) && (doc['mois'].value.getMonthValue()==4)",
                        "lang": "painless"
                    }
                }
            },
            "must": {
                "bool": {
                    "should": [
                        {"term" : {"numid": 51237}},
                        {"term" : {"numid": 13798}},
                        {"term" : {"numid": 10764}},
                        {"term" : {"numid": 12909}},
                        {"term" : {"numid": 12445}},
                        {"term" : {"numid": 12946}},
                        {"term" : {"numid": 13007}}                     
                    ]
                }
            }
            
        }
    },
    "aggs": {
        "sum_download": {
            "sum": {
                "script": {
                    "source": "doc['download']"
                }
            }
        },
        "sum_upload": {
            "sum": {
                "script": {
                    "source": "doc['upload']"
                }
            }
        }
    }
}

```

The bool / must / should queries are what I'm able to transcript to Java.  
But the script / aggs ones... are harder.

Have you got any kind of tutorial for that use case of transcripting this to Java REST High or Low Level Client?

Thank you.

---

<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:** [November 18, 2019, 1:08pm UTC](https://discuss.elastic.co/t/json-with-script-and-aggregation-query-to-java-rest-high-or-low-level-client/204477/2 "2019-11-18T13:08:41Z")

</div>

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