0

Is there a Java code equivalent to this sub aggregation. I need Java code to build the sub aggregation object.

{
  "query": {
    "SOME BOOL QUERIES HERE"
  },
 "aggs" : {
        "trs_timestamp" : {
            "date_histogram" : {
                "field" : "trs_timestamp",
                "interval" : "day"
            },
        "aggs" : {
                "AvgTT" : { "avg" : { "field" : "action_time" }},
                "AvgST" : { "avg" : { "field" : "st" }},
                "AvgCALC" : { "avg" : { "field" : "ncalc" }},
                "AvgRC" : { "avg" : { "field" : "rc" }},
                "AvgFR" : { "avg" : { "field" : "st" }}
            }
        }
    } 
}


2 Answers 2

2

You can use Elasticsearch Java API and AggregationBuilders for this, e.g.:

SearchResponse response = client.prepareSearch()
        .addAggregation(AggregationBuilders.avg("AvgTT").field("action_time"))
        .addAggregation(AggregationBuilders.avg("AvgST").field("st"))
        .addAggregation(AggregationBuilders.avg("AvgCALC").field("ncalc"))
        .addAggregation(AggregationBuilders.avg("AvgRC").field("rc"))
        .addAggregation(AggregationBuilders.avg("AvgFR").field("st"))
        .execute()
        .actionGet();
Sign up to request clarification or add additional context in comments.

Comments

0

By example:

SearchResponse sr = node.client().prepareSearch()
        .setQuery( /* your query */ )
        .addAggregation( /* add an aggregation */ )
        .execute().actionGet();

You can see that there is addAggregation not set implying that you can add multiple aggregations to a query. https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-aggs.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.