Java API for multiple sub-aggregations


(Saravanan Shanmugasundaram) #1

Hi,

I am trying to find out the JAVA API that supports nested sub-aggregations in ES. However, the current API's doesn't provide the clear implementation.

Req: property1 , property 2 .... property n

Using TermBuilder, when i tried adding the subAggregation of subAggregation, its getting added into the TermsBuilder as list of sub-aggregrations rather than nested sub-aggregations.

Thanks,
Saravanan.


(Ha Lan Quyen) #2

I'm having the same problem and using sub-aggregation of sub-aggregation
but it's difficult to parse response because will have to use many loop and
I think it's not good way

On Saturday, May 3, 2014 2:31:08 AM UTC+7, Saravanan S wrote:

Hi,

I am trying to find out the JAVA API that supports nested sub-aggregations
in ES. However, the current API's doesn't provide the clear
implementation.

Req: property1 , property 2 .... property n

Using TermBuilder, when i tried adding the subAggregation of
subAggregation,
its getting added into the TermsBuilder as list of sub-aggregrations
rather
than nested sub-aggregations.

Thanks,
Saravanan.

--
View this message in context:
http://elasticsearch-users.115913.n3.nabble.com/Java-API-for-multiple-sub-aggregations-tp4055253.html
Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/d1f96bb8-1020-4c02-ab4f-e24bf033a4a4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


(bappr) #3

Hi,

A possible solution is :

TermsBuilder termsBuilder = null;
TermsBuilder root = null;
if (!aggregs.isEmpty()) {
for (Aggreg aggreg : aggregs) {
if (aggreg.aggregOk()) {
if (aggreg.isTerms()) {
if (termsBuilder != null) {
TermsBuilder temp = terms(aggreg.getKey()).field(aggreg.getField()).minDocCount(0).size(0);
termsBuilder = termsBuilder.subAggregation(temp);
termsBuilder = temp;
} else {
termsBuilder = terms(aggreg.getKey()).field(aggreg.getField()).minDocCount(0).size(0);
root = termsBuilder;
}
}
}
}
}
termsBuilder = root;

Ben


(system) #4