Hello.
I struggle to do aggregations on multiple terms using the new Java API, whenever using loops.
I have a map of terms I need to aggregate on with their renamed value that I need to loop on.
I have tried the following code, but I can't return the builder instead of the aggregations.
co.elastic.clients.elasticsearch.core.SearchRequest.Builder searchBuilder = co.elastic.clients.elasticsearch.core.SearchRequest.of(b1 -> b1
.aggregations("agg", (b2, c2) -> {
for (Map.Entry<String, String> fieldEntry : fieldNames.entrySet()) {
String esField = fieldEntry.getKey();
String renamedValue : fieldNames.get(esField);
b2.terms(b3 ->
b3.field(esField)
.missingBucket(true)
.name(renamedValue)
);
}
return b2;
}
)
.size(0)
);
How should I change the code to solve this issue ?
I am using the version 7.16.3 of the new Java API.
Thanks