• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java AvgBuilder类的典型用法和代码示例

java 2次浏览

本文整理汇总了Java中org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder的典型用法代码示例。如果您正苦于以下问题:Java AvgBuilder类的具体用法?Java AvgBuilder怎么用?Java AvgBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。

AvgBuilder类属于org.elasticsearch.search.aggregations.metrics.avg包,在下文中一共展示了AvgBuilder类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: avgQuery

点赞 3

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
public static void avgQuery(Client client ) {
	SearchResponse res = null;
	AvgBuilder agg = AggregationBuilders
			.avg("avg_num")
			.field("like");
	
	res = client.prepareSearch("search_test")
			.setTypes("article")
			.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
			.addAggregation(agg)
			.setFrom(0)
			.setSize(10)
			.execute().actionGet();
	System.out.println(res);
	
	// on shutdown
	client.close();
}
 

开发者ID:walle-liao,
项目名称:jaf-examples,
代码行数:19,
代码来源:AggsQueryTest.java

示例2: getNodeTimeseriesStatistics

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
@Override
public List<NodeTimeseriesStatistics> getNodeTimeseriesStatistics(String tenantId, Criteria criteria, long interval) {
    String index = client.getIndex(tenantId);
    if (!refresh(index)) {
        return null;
    }

    AvgBuilder avgBuilder = AggregationBuilders
            .avg("avg")
            .field(ElasticsearchUtil.ACTUAL_FIELD);

    TermsBuilder componentsBuilder = AggregationBuilders
            .terms("components")
            .field("componentType")
            .size(criteria.getMaxResponseSize())
            .subAggregation(avgBuilder);

    DateHistogramBuilder histogramBuilder = AggregationBuilders
            .dateHistogram("histogram")
            .interval(interval)
            .field(ElasticsearchUtil.TIMESTAMP_FIELD)
            .subAggregation(componentsBuilder);

    BoolQueryBuilder query = buildQuery(criteria, ElasticsearchUtil.TRANSACTION_FIELD, NodeDetails.class);
    SearchRequestBuilder request = getNodeDetailsRequest(index, criteria, query, 0)
            .addAggregation(histogramBuilder);

    SearchResponse response = getSearchResponse(request);
    DateHistogram histogram = response.getAggregations().get("histogram");

    return histogram.getBuckets().stream()
            .map(AnalyticsServiceElasticsearch::toNodeTimeseriesStatistics)
            .collect(Collectors.toList());
}
 

开发者ID:hawkular,
项目名称:hawkular-apm,
代码行数:35,
代码来源:AnalyticsServiceElasticsearch.java

示例3: newAvg

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
public static AbstractAggregationBuilder newAvg(Function func) {
	AvgBuilder avg;
	if (func.fieldtype == Field.SCRIPT)
		avg = AggregationBuilders.avg(Function.genStatField(func))
				.script(func.field);
	else
		avg = AggregationBuilders.avg(Function.genStatField(func))
				.field(func.field);

	return avg;
}
 

开发者ID:huangchen007,
项目名称:elasticsearch-rest-command,
代码行数:12,
代码来源:AST_Stats.java

示例4: avg

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
/**
 * Create a new {@link Avg} aggregation with the given name.
 */
public static AvgBuilder avg(String name) {
    return new AvgBuilder(name);
}
 

开发者ID:baidu,
项目名称:Elasticsearch,
代码行数:7,
代码来源:AggregationBuilders.java

示例5: assertTop10of50OneShardNestedAggregations

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
@Test
public void assertTop10of50OneShardNestedAggregations() {
    client.admin().indices().prepareCreate("topk-4").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 1)).execute().actionGet();
    
    double sum = 0;
    for (int i = 0; i < 50; ++i) { // 50 values
        client.prepareIndex("topk-4", "type0", "doc" + i).setSource("{ \"field0\": \"foo" + i + "\", \"field1\":" + i +" }").setRefresh(true).execute().actionGet();
    }
    
    // foo0 x 50
    for (int i = 50; i < 100; ++i) {
        client.prepareIndex("topk-4", "type0", "doc" + i).setSource("{ \"field0\": \"foo0\", \"field1\":" + i +" }").setRefresh(true).execute().actionGet();
        sum += i;
    }
   
    SearchResponse searchResponse = client.prepareSearch("topk-4")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10)
                    .subAggregation(new AvgBuilder("avg").field("field1"))
                    .subAggregation(new MaxBuilder("max").field("field1"))
            )
            .execute().actionGet();
    assertEquals(100, searchResponse.getHits().getTotalHits());
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(10, buckets.size());
    assertEquals("foo0", buckets.get(0).getKey());
    assertEquals(51, buckets.get(0).getDocCount());
    assertEquals(2, buckets.get(0).getAggregations().asList().size());
    for (Aggregation agg : buckets.get(0).getAggregations()) {
        switch (agg.getName()) {
        case "avg":
            assertEquals(sum / 51, ((Avg) agg).getValue(), 0.01);
            break;
        case "max":
            assertEquals(99.0, ((Max) agg).getValue(), 0.001);
            break;
        default:
            assertTrue(false);
        } 
    }
}
 

开发者ID:algolia,
项目名称:elasticsearch-topk-plugin,
代码行数:44,
代码来源:SimpleTests.java

示例6: assertTop10of50TwoShardNestedAggregations

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
@Test
public void assertTop10of50TwoShardNestedAggregations() {
    client.admin().indices().prepareCreate("topk-5").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 2)).execute().actionGet();
    
    double sum = 0;
    for (int i = 0; i < 50; ++i) { // 50 values
        client.prepareIndex("topk-5", "type0", "doc" + i).setSource("{ \"field0\": \"foo" + i + "\", \"field1\":" + i +" }").setRefresh(true).execute().actionGet();
    }
    
    // foo0 x 50
    for (int i = 50; i < 100; ++i) {
        client.prepareIndex("topk-5", "type0", "doc" + i).setSource("{ \"field0\": \"foo0\", \"field1\":" + i +" }").setRefresh(true).execute().actionGet();
        sum += i;
    }
   
    SearchResponse searchResponse = client.prepareSearch("topk-5")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10)
                    .subAggregation(new AvgBuilder("avg").field("field1"))
                    .subAggregation(new MaxBuilder("max").field("field1"))
            )
            .execute().actionGet();
    assertEquals(100, searchResponse.getHits().getTotalHits());
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(10, buckets.size());
    assertEquals("foo0", buckets.get(0).getKey());
    assertEquals(51, buckets.get(0).getDocCount());
    assertEquals(2, buckets.get(0).getAggregations().asList().size());
    for (Aggregation agg : buckets.get(0).getAggregations()) {
        switch (agg.getName()) {
        case "avg":
            assertEquals(sum / 51, ((Avg) agg).getValue(), 0.01);
            break;
        case "max":
            assertEquals(99.0, ((Max) agg).getValue(), 0.001);
            break;
        default:
            assertTrue(false);
        } 
    }
}
 

开发者ID:algolia,
项目名称:elasticsearch-topk-plugin,
代码行数:44,
代码来源:SimpleTests.java

示例7: assertTop10of50TwoShardNestedAggregationsStress

点赞 2

import org.elasticsearch.search.aggregations.metrics.avg.AvgBuilder; //导入依赖的package包/类
@Test
public void assertTop10of50TwoShardNestedAggregationsStress() {
    client.admin().indices().prepareCreate("topk-6").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 4)).execute().actionGet();
    
    final int N = 30000;
    double sum = 0;
    int n = 0;
    int max = Integer.MIN_VALUE;
    Random r = new Random();
    for (int i = 0; i < N; ++i) {
        int v = r.nextInt();
        if (i % 7 == 0) {
            sum += v;
            ++n;
            if (v > max) {
                max = v;
            }
        }
        client.prepareIndex("topk-6", "type0", "doc" + i).setSource("{ \"field0\": \"foo" + (i % 7 == 0 ? "bar" : String.valueOf(i)) + "\", \"field1\":" + v +" }").setRefresh(i == N - 1).execute().actionGet();
    }
    try { Thread.sleep(2000); } catch (InterruptedException e) {} // FIXME: wait until all docs are searchable
    
    SearchResponse searchResponse = client.prepareSearch("topk-6")
            .setQuery(matchAllQuery())
            .addAggregation(new TopKBuilder("topk").field("field0").size(10)
                    .subAggregation(new AvgBuilder("avg").field("field1"))
                    .subAggregation(new MaxBuilder("max").field("field1"))
            )
            .execute().actionGet();
    assertEquals(N, searchResponse.getHits().getTotalHits());
    TopK topk = searchResponse.getAggregations().get("topk");
    assertNotNull(topk);
    List<TopK.Bucket> buckets = new ArrayList<>(topk.getBuckets());
    assertEquals(10, buckets.size());
    assertEquals("foobar", buckets.get(0).getKey());
    assertEquals(n, buckets.get(0).getDocCount());
    assertEquals(2, buckets.get(0).getAggregations().asList().size());
    for (Aggregation agg : buckets.get(0).getAggregations()) {
        switch (agg.getName()) {
        case "avg":
            assertEquals(sum / n, ((Avg) agg).getValue(), 0.01);
            break;
        case "max":
            assertEquals((double) max, ((Max) agg).getValue(), 0.001);
            break;
        default:
            assertTrue(false);
        } 
    }
}
 

开发者ID:algolia,
项目名称:elasticsearch-topk-plugin,
代码行数:51,
代码来源:SimpleTests.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)