elasticsearch Java API中的多个平均聚合

是否有与此子聚合等效的 Java 代码。我需要 Java 代码来构建子聚合对象。


{

  "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" }}

            }

        }

    } 

}


白衣染霜花
浏览 162回答 2
2回答

千巷猫影

您可以使用 Elasticsearch Java API 并AggregationBuilders为此,例如: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();

慕娘9325324

举例:SearchResponse sr = node.client().prepareSearch()         .setQuery( /* your query */ )         .addAggregation( /* add an aggregation */ )         .execute().actionGet();您可以看到,这addAggregation并不set意味着您可以向查询添加多个聚合。 https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-aggs.html
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java