Search in sources :

Example 41 with Histogram

use of org.elasticsearch.search.aggregations.bucket.histogram.Histogram in project elasticsearch by elastic.

the class ShardReduceIT method testRange.

public void testRange() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(range("range").field("value").addRange("r1", 0, 10).subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    Range range = response.getAggregations().get("range");
    Histogram histo = range.getBuckets().get(0).getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Range(org.elasticsearch.search.aggregations.bucket.range.Range) AggregationBuilders.dateRange(org.elasticsearch.search.aggregations.AggregationBuilders.dateRange) AggregationBuilders.ipRange(org.elasticsearch.search.aggregations.AggregationBuilders.ipRange) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 42 with Histogram

use of org.elasticsearch.search.aggregations.bucket.histogram.Histogram in project elasticsearch by elastic.

the class ShardReduceIT method testHistogram.

public void testHistogram() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(histogram("topHisto").field("value").interval(5).subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    Histogram topHisto = response.getAggregations().get("topHisto");
    Histogram histo = topHisto.getBuckets().get(0).getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 43 with Histogram

use of org.elasticsearch.search.aggregations.bucket.histogram.Histogram in project elasticsearch by elastic.

the class ShardReduceIT method testDateHistogram.

public void testDateHistogram() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(dateHistogram("topHisto").field("date").dateHistogramInterval(DateHistogramInterval.MONTH).subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    Histogram topHisto = response.getAggregations().get("topHisto");
    Histogram histo = topHisto.getBuckets().iterator().next().getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 44 with Histogram

use of org.elasticsearch.search.aggregations.bucket.histogram.Histogram in project elasticsearch by elastic.

the class ShardReduceIT method testMissing.

public void testMissing() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(missing("missing").field("foobar").subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    Missing missing = response.getAggregations().get("missing");
    Histogram histo = missing.getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Missing(org.elasticsearch.search.aggregations.bucket.missing.Missing) Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 45 with Histogram

use of org.elasticsearch.search.aggregations.bucket.histogram.Histogram in project elasticsearch by elastic.

the class ShardReduceIT method testDateRange.

public void testDateRange() throws Exception {
    SearchResponse response = client().prepareSearch("idx").setQuery(QueryBuilders.matchAllQuery()).addAggregation(dateRange("range").field("date").addRange("r1", "2014-01-01", "2014-01-10").subAggregation(dateHistogram("histo").field("date").dateHistogramInterval(DateHistogramInterval.DAY).minDocCount(0))).execute().actionGet();
    assertSearchResponse(response);
    Range range = response.getAggregations().get("range");
    Histogram histo = range.getBuckets().get(0).getAggregations().get("histo");
    assertThat(histo.getBuckets().size(), equalTo(4));
}
Also used : Histogram(org.elasticsearch.search.aggregations.bucket.histogram.Histogram) AggregationBuilders.dateHistogram(org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram) Range(org.elasticsearch.search.aggregations.bucket.range.Range) AggregationBuilders.dateRange(org.elasticsearch.search.aggregations.AggregationBuilders.dateRange) AggregationBuilders.ipRange(org.elasticsearch.search.aggregations.AggregationBuilders.ipRange) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

Histogram (org.elasticsearch.search.aggregations.bucket.histogram.Histogram)210 SearchResponse (org.elasticsearch.action.search.SearchResponse)208 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)202 Bucket (org.elasticsearch.search.aggregations.bucket.histogram.Histogram.Bucket)121 AggregationBuilders.dateHistogram (org.elasticsearch.search.aggregations.AggregationBuilders.dateHistogram)60 Sum (org.elasticsearch.search.aggregations.metrics.sum.Sum)43 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)37 ArrayList (java.util.ArrayList)36 DateTime (org.joda.time.DateTime)34 Script (org.elasticsearch.script.Script)32 InternalBucketMetricValue (org.elasticsearch.search.aggregations.pipeline.bucketmetrics.InternalBucketMetricValue)11 HashMap (java.util.HashMap)10 PipelineAggregatorBuilders.bucketScript (org.elasticsearch.search.aggregations.pipeline.PipelineAggregatorBuilders.bucketScript)10 PipelineAggregationHelperTests (org.elasticsearch.search.aggregations.pipeline.PipelineAggregationHelperTests)8 Matchers.containsString (org.hamcrest.Matchers.containsString)8 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)7 Filter (org.elasticsearch.search.aggregations.bucket.filter.Filter)6 Range (org.elasticsearch.search.aggregations.bucket.range.Range)6 PercentilesBucket (org.elasticsearch.search.aggregations.pipeline.bucketmetrics.percentile.PercentilesBucket)6 ExtendedStatsBucket (org.elasticsearch.search.aggregations.pipeline.bucketmetrics.stats.extended.ExtendedStatsBucket)6