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")
.subAggregation(AggregationBuilders.terms("subtypes"))
.field("subtypes.keyword");
var searchRequest = new SearchRequest("index");
var sourceBuilder = new SearchSourceBuilder();
sourceBuilder.size(0);
sourceBuilder.aggregation(aags);
searchRequest.source(sourceBuilder);
var response = esClient.search(searchRequest, RequestOptions.DEFAULT);
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.