Datehistogram aggregation query using java api client

Need to convert this to java api client code
"aggregations":{"dateHistogram":{"date_histogram":{"field":"createTime","interval":"6h","offset":0,"order":{"_key":"asc"},"keyed":false,"min_doc_count":0,"extended_bounds":{"min":1709577360000,"max":1712169360000}},"aggregations":{"terms":{"terms":{"field":"effectedObject.keyword","size":5,"min_doc_count":1,"shard_min_doc_count":0,"show_term_doc_count_error":false,"order":[{"aggs":"desc"},{"_key":"asc"}]},"aggregations":{"aggs":{"min":{"field":"holdFolder"}}}}}}}'

Able to create datehistogram aggregation but facing issue in adding metrics sub aggregation(min aggregation in this case) to terms aggregation

can someone assist here?

Please be patient in waiting for responses to your question and refrain from pinging multiple times asking for a response or opening multiple topics for the same question. This is a community forum, it may take time for someone to reply to your question. For more information please refer to the Community Code of Conduct specifically the section "Be patient". Also, please refrain from pinging folks directly, this is a forum and anyone that participates might be able to assist you.

If you are in need of a service with an SLA that covers response times for questions then you may want to consider talking to us about a subscription.

It's fine to answer on your own thread after 2 or 3 days (not including weekends) if you don't have an answer.

Sorry about that. I will wait.

Hello,
Subaggregations in the java client can be added by calling the aggregations method provided in the Aggregation class itself; your example would look something like this:

        esClient.search(s -> s
                .index("index")
                .aggregations("dateHistogram", a1 -> a1
                    .dateHistogram(dh -> dh
                        .field("createTime")
                        ...)
                    .aggregations("terms", a2 -> a2
                        .terms(ts -> ts
                            .field("effectedObject.keyword")
                            ...)
                        .aggregations("aggs", a3 -> a3
                            .min(m -> m
                                .field("holdFolder")))))
            ,Object.class);

Thanks..it worked

1 Like