コード例 #1
0
  @Test
  public void withStatsSubAggregator() throws Exception {
    SearchResponse response =
        client()
            .prepareSearch("idx")
            .setQuery(QueryBuilders.termQuery("tag", "tag1"))
            .addAggregation(global("global").subAggregation(stats("value_stats").field("value")))
            .execute()
            .actionGet();

    assertSearchResponse(response);

    Global global = response.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo((long) numDocs));
    assertThat(global.getAggregations().asList().isEmpty(), is(false));

    Stats stats = global.getAggregations().get("value_stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("value_stats"));
    long sum = 0;
    for (int i = 0; i < numDocs; ++i) {
      sum += i + 1;
    }
    assertThat(stats.getAvg(), equalTo((double) sum / numDocs));
    assertThat(stats.getMin(), equalTo(1.0));
    assertThat(stats.getMax(), equalTo((double) numDocs));
    assertThat(stats.getCount(), equalTo((long) numDocs));
    assertThat(stats.getSum(), equalTo((double) sum));
  }
コード例 #2
0
ファイル: MaxIT.java プロジェクト: nellicus/elasticsearch
  @Override
  @Test
  public void testSingleValuedField_getProperty() throws Exception {

    SearchResponse searchResponse =
        client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(global("global").subAggregation(max("max").field("value")))
            .execute()
            .actionGet();

    assertHitCount(searchResponse, 10);

    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10l));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));

    Max max = global.getAggregations().get("max");
    assertThat(max, notNullValue());
    assertThat(max.getName(), equalTo("max"));
    double expectedMaxValue = 10.0;
    assertThat(max.getValue(), equalTo(expectedMaxValue));
    assertThat((Max) global.getProperty("max"), equalTo(max));
    assertThat((double) global.getProperty("max.value"), equalTo(expectedMaxValue));
    assertThat((double) max.getProperty("value"), equalTo(expectedMaxValue));
  }
コード例 #3
0
ファイル: AvgIT.java プロジェクト: martinstuga/elasticsearch
  @Override
  public void testSingleValuedFieldGetProperty() throws Exception {

    SearchResponse searchResponse =
        client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(global("global").subAggregation(avg("avg").field("value")))
            .execute()
            .actionGet();

    assertHitCount(searchResponse, 10);

    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10l));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));

    Avg avg = global.getAggregations().get("avg");
    assertThat(avg, notNullValue());
    assertThat(avg.getName(), equalTo("avg"));
    double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
    assertThat(avg.getValue(), equalTo(expectedAvgValue));
    assertThat((Avg) global.getProperty("avg"), equalTo(avg));
    assertThat((double) global.getProperty("avg.value"), equalTo(expectedAvgValue));
    assertThat((double) avg.getProperty("value"), equalTo(expectedAvgValue));
  }
コード例 #4
0
  @Override
  public void testSingleValuedFieldGetProperty() throws Exception {
    final double[] pcts = randomPercentiles();
    SearchResponse searchResponse =
        client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(
                global("global")
                    .subAggregation(
                        randomCompression(percentiles("percentiles"))
                            .field("value")
                            .percentiles(pcts)))
            .execute()
            .actionGet();

    assertHitCount(searchResponse, 10);

    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10L));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));

    Percentiles percentiles = global.getAggregations().get("percentiles");
    assertThat(percentiles, notNullValue());
    assertThat(percentiles.getName(), equalTo("percentiles"));
    assertThat(global.getProperty("percentiles"), sameInstance(percentiles));
  }
コード例 #5
0
  @Override
  public void testSingleValuedFieldGetProperty() throws Exception {
    SearchResponse searchResponse =
        client()
            .prepareSearch("idx")
            .setQuery(matchAllQuery())
            .addAggregation(global("global").subAggregation(stats("stats").field("value")))
            .execute()
            .actionGet();

    assertHitCount(searchResponse, 10);

    Global global = searchResponse.getAggregations().get("global");
    assertThat(global, notNullValue());
    assertThat(global.getName(), equalTo("global"));
    assertThat(global.getDocCount(), equalTo(10L));
    assertThat(global.getAggregations(), notNullValue());
    assertThat(global.getAggregations().asMap().size(), equalTo(1));

    Stats stats = global.getAggregations().get("stats");
    assertThat(stats, notNullValue());
    assertThat(stats.getName(), equalTo("stats"));
    Stats statsFromProperty = (Stats) global.getProperty("stats");
    assertThat(statsFromProperty, notNullValue());
    assertThat(statsFromProperty, sameInstance(stats));
    double expectedAvgValue = (double) (1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10) / 10;
    assertThat(stats.getAvg(), equalTo(expectedAvgValue));
    assertThat((double) global.getProperty("stats.avg"), equalTo(expectedAvgValue));
    double expectedMinValue = 1.0;
    assertThat(stats.getMin(), equalTo(expectedMinValue));
    assertThat((double) global.getProperty("stats.min"), equalTo(expectedMinValue));
    double expectedMaxValue = 10.0;
    assertThat(stats.getMax(), equalTo(expectedMaxValue));
    assertThat((double) global.getProperty("stats.max"), equalTo(expectedMaxValue));
    double expectedSumValue = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
    assertThat(stats.getSum(), equalTo(expectedSumValue));
    assertThat((double) global.getProperty("stats.sum"), equalTo(expectedSumValue));
    long expectedCountValue = 10;
    assertThat(stats.getCount(), equalTo(expectedCountValue));
    assertThat((double) global.getProperty("stats.count"), equalTo((double) expectedCountValue));
  }