How to implement this ES curl into Java

Hi, I want to translate this curl into working java code in spring -
curl -XGET 'localhost:9200/catalog/_search?pretty' -H 'Content-Type: application/json' -d' { "size": 0,
"aggs": { "types": {
"terms": {
"field": "types.keyword"
"aggs": {
"subtypes": {
"terms": {
"field": "subtypes.keyword"
Here I am using sub aggregation.

If you are using Java High Level Client, try:

  var aags = AggregationBuilders.terms("types").field("types.keyword")
    var searchRequest = new SearchRequest("index");
    var sourceBuilder = new SearchSourceBuilder();
    var response =, RequestOptions.DEFAULT);

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