Search in sources :

Example 1 with LongTerms

use of org.elasticsearch.search.aggregations.bucket.terms.LongTerms in project elasticsearch by elastic.

the class SearchModule method registerAggregations.

private void registerAggregations(List<SearchPlugin> plugins) {
    registerAggregation(new AggregationSpec(AvgAggregationBuilder.NAME, AvgAggregationBuilder::new, AvgAggregationBuilder::parse).addResultReader(InternalAvg::new));
    registerAggregation(new AggregationSpec(SumAggregationBuilder.NAME, SumAggregationBuilder::new, SumAggregationBuilder::parse).addResultReader(InternalSum::new));
    registerAggregation(new AggregationSpec(MinAggregationBuilder.NAME, MinAggregationBuilder::new, MinAggregationBuilder::parse).addResultReader(InternalMin::new));
    registerAggregation(new AggregationSpec(MaxAggregationBuilder.NAME, MaxAggregationBuilder::new, MaxAggregationBuilder::parse).addResultReader(InternalMax::new));
    registerAggregation(new AggregationSpec(StatsAggregationBuilder.NAME, StatsAggregationBuilder::new, StatsAggregationBuilder::parse).addResultReader(InternalStats::new));
    registerAggregation(new AggregationSpec(ExtendedStatsAggregationBuilder.NAME, ExtendedStatsAggregationBuilder::new, ExtendedStatsAggregationBuilder::parse).addResultReader(InternalExtendedStats::new));
    registerAggregation(new AggregationSpec(ValueCountAggregationBuilder.NAME, ValueCountAggregationBuilder::new, ValueCountAggregationBuilder::parse).addResultReader(InternalValueCount::new));
    registerAggregation(new AggregationSpec(PercentilesAggregationBuilder.NAME, PercentilesAggregationBuilder::new, PercentilesAggregationBuilder::parse).addResultReader(InternalTDigestPercentiles.NAME, InternalTDigestPercentiles::new).addResultReader(InternalHDRPercentiles.NAME, InternalHDRPercentiles::new));
    registerAggregation(new AggregationSpec(PercentileRanksAggregationBuilder.NAME, PercentileRanksAggregationBuilder::new, PercentileRanksAggregationBuilder::parse).addResultReader(InternalTDigestPercentileRanks.NAME, InternalTDigestPercentileRanks::new).addResultReader(InternalHDRPercentileRanks.NAME, InternalHDRPercentileRanks::new));
    registerAggregation(new AggregationSpec(CardinalityAggregationBuilder.NAME, CardinalityAggregationBuilder::new, CardinalityAggregationBuilder::parse).addResultReader(InternalCardinality::new));
    registerAggregation(new AggregationSpec(GlobalAggregationBuilder.NAME, GlobalAggregationBuilder::new, GlobalAggregationBuilder::parse).addResultReader(InternalGlobal::new));
    registerAggregation(new AggregationSpec(MissingAggregationBuilder.NAME, MissingAggregationBuilder::new, MissingAggregationBuilder::parse).addResultReader(InternalMissing::new));
    registerAggregation(new AggregationSpec(FilterAggregationBuilder.NAME, FilterAggregationBuilder::new, FilterAggregationBuilder::parse).addResultReader(InternalFilter::new));
    registerAggregation(new AggregationSpec(FiltersAggregationBuilder.NAME, FiltersAggregationBuilder::new, FiltersAggregationBuilder::parse).addResultReader(InternalFilters::new));
    registerAggregation(new AggregationSpec(AdjacencyMatrixAggregationBuilder.NAME, AdjacencyMatrixAggregationBuilder::new, AdjacencyMatrixAggregationBuilder.getParser()).addResultReader(InternalAdjacencyMatrix::new));
    registerAggregation(new AggregationSpec(SamplerAggregationBuilder.NAME, SamplerAggregationBuilder::new, SamplerAggregationBuilder::parse).addResultReader(InternalSampler.NAME, InternalSampler::new).addResultReader(UnmappedSampler.NAME, UnmappedSampler::new));
    registerAggregation(new AggregationSpec(DiversifiedAggregationBuilder.NAME, DiversifiedAggregationBuilder::new, DiversifiedAggregationBuilder::parse));
    registerAggregation(new AggregationSpec(TermsAggregationBuilder.NAME, TermsAggregationBuilder::new, TermsAggregationBuilder::parse).addResultReader(StringTerms.NAME, StringTerms::new).addResultReader(UnmappedTerms.NAME, UnmappedTerms::new).addResultReader(LongTerms.NAME, LongTerms::new).addResultReader(DoubleTerms.NAME, DoubleTerms::new));
    registerAggregation(new AggregationSpec(SignificantTermsAggregationBuilder.NAME, SignificantTermsAggregationBuilder::new, SignificantTermsAggregationBuilder.getParser(significanceHeuristicParserRegistry)).addResultReader(SignificantStringTerms.NAME, SignificantStringTerms::new).addResultReader(SignificantLongTerms.NAME, SignificantLongTerms::new).addResultReader(UnmappedSignificantTerms.NAME, UnmappedSignificantTerms::new));
    registerAggregation(new AggregationSpec(RangeAggregationBuilder.NAME, RangeAggregationBuilder::new, RangeAggregationBuilder::parse).addResultReader(InternalRange::new));
    registerAggregation(new AggregationSpec(DateRangeAggregationBuilder.NAME, DateRangeAggregationBuilder::new, DateRangeAggregationBuilder::parse).addResultReader(InternalDateRange::new));
    registerAggregation(new AggregationSpec(IpRangeAggregationBuilder.NAME, IpRangeAggregationBuilder::new, IpRangeAggregationBuilder::parse).addResultReader(InternalBinaryRange::new));
    registerAggregation(new AggregationSpec(HistogramAggregationBuilder.NAME, HistogramAggregationBuilder::new, HistogramAggregationBuilder::parse).addResultReader(InternalHistogram::new));
    registerAggregation(new AggregationSpec(DateHistogramAggregationBuilder.NAME, DateHistogramAggregationBuilder::new, DateHistogramAggregationBuilder::parse).addResultReader(InternalDateHistogram::new));
    registerAggregation(new AggregationSpec(GeoDistanceAggregationBuilder.NAME, GeoDistanceAggregationBuilder::new, GeoDistanceAggregationBuilder::parse).addResultReader(InternalGeoDistance::new));
    registerAggregation(new AggregationSpec(GeoGridAggregationBuilder.NAME, GeoGridAggregationBuilder::new, GeoGridAggregationBuilder::parse).addResultReader(InternalGeoHashGrid::new));
    registerAggregation(new AggregationSpec(NestedAggregationBuilder.NAME, NestedAggregationBuilder::new, NestedAggregationBuilder::parse).addResultReader(InternalNested::new));
    registerAggregation(new AggregationSpec(ReverseNestedAggregationBuilder.NAME, ReverseNestedAggregationBuilder::new, ReverseNestedAggregationBuilder::parse).addResultReader(InternalReverseNested::new));
    registerAggregation(new AggregationSpec(TopHitsAggregationBuilder.NAME, TopHitsAggregationBuilder::new, TopHitsAggregationBuilder::parse).addResultReader(InternalTopHits::new));
    registerAggregation(new AggregationSpec(GeoBoundsAggregationBuilder.NAME, GeoBoundsAggregationBuilder::new, GeoBoundsAggregationBuilder::parse).addResultReader(InternalGeoBounds::new));
    registerAggregation(new AggregationSpec(GeoCentroidAggregationBuilder.NAME, GeoCentroidAggregationBuilder::new, GeoCentroidAggregationBuilder::parse).addResultReader(InternalGeoCentroid::new));
    registerAggregation(new AggregationSpec(ScriptedMetricAggregationBuilder.NAME, ScriptedMetricAggregationBuilder::new, ScriptedMetricAggregationBuilder::parse).addResultReader(InternalScriptedMetric::new));
    registerAggregation(new AggregationSpec(ChildrenAggregationBuilder.NAME, ChildrenAggregationBuilder::new, ChildrenAggregationBuilder::parse).addResultReader(InternalChildren::new));
    registerFromPlugin(plugins, SearchPlugin::getAggregations, this::registerAggregation);
}
Also used : ReverseNestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) StatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.StatsAggregationBuilder) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) PipelineAggregationSpec(org.elasticsearch.plugins.SearchPlugin.PipelineAggregationSpec) AggregationSpec(org.elasticsearch.plugins.SearchPlugin.AggregationSpec) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) IpRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) ScriptedMetricAggregationBuilder(org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetricAggregationBuilder) ValueCountAggregationBuilder(org.elasticsearch.search.aggregations.metrics.valuecount.ValueCountAggregationBuilder) MaxAggregationBuilder(org.elasticsearch.search.aggregations.metrics.max.MaxAggregationBuilder) AdjacencyMatrixAggregationBuilder(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder) StringTerms(org.elasticsearch.search.aggregations.bucket.terms.StringTerms) SignificantStringTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantStringTerms) GeoDistanceAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregationBuilder) InternalTDigestPercentiles(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentiles) FiltersAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder) GeoBoundsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geobounds.GeoBoundsAggregationBuilder) AvgAggregationBuilder(org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder) NestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder) ReverseNestedAggregationBuilder(org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) IpRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.ip.IpRangeAggregationBuilder) FilterAggregationBuilder(org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder) SignificantLongTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms) TopHitsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.tophits.TopHitsAggregationBuilder) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) InternalTDigestPercentileRanks(org.elasticsearch.search.aggregations.metrics.percentiles.tdigest.InternalTDigestPercentileRanks) GeoCentroidAggregationBuilder(org.elasticsearch.search.aggregations.metrics.geocentroid.GeoCentroidAggregationBuilder) MissingAggregationBuilder(org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder) ChildrenAggregationBuilder(org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder) InternalSampler(org.elasticsearch.search.aggregations.bucket.sampler.InternalSampler) GlobalAggregationBuilder(org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder) SumAggregationBuilder(org.elasticsearch.search.aggregations.metrics.sum.SumAggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) GeoGridAggregationBuilder(org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder) SearchPlugin(org.elasticsearch.plugins.SearchPlugin) MinAggregationBuilder(org.elasticsearch.search.aggregations.metrics.min.MinAggregationBuilder) CardinalityAggregationBuilder(org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder) LongTerms(org.elasticsearch.search.aggregations.bucket.terms.LongTerms) SignificantLongTerms(org.elasticsearch.search.aggregations.bucket.significant.SignificantLongTerms) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder)

Example 2 with LongTerms

use of org.elasticsearch.search.aggregations.bucket.terms.LongTerms in project elasticsearch by elastic.

the class NestedIT method testNestedWithSubTermsAgg.

public void testNestedWithSubTermsAgg() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(nested("nested", "nested").subAggregation(terms("values").field("nested.value").size(100).collectMode(aggCollectionMode))).execute().actionGet();
    assertSearchResponse(response);
    long docCount = 0;
    long[] counts = new long[numParents + 6];
    for (int i = 0; i < numParents; ++i) {
        for (int j = 0; j < numChildren[i]; ++j) {
            final int value = i + 1 + j;
            ++counts[value];
            ++docCount;
        }
    }
    int uniqueValues = 0;
    for (long count : counts) {
        if (count > 0) {
            ++uniqueValues;
        }
    }
    Nested nested = response.getAggregations().get("nested");
    assertThat(nested, notNullValue());
    assertThat(nested.getName(), equalTo("nested"));
    assertThat(nested.getDocCount(), equalTo(docCount));
    assertThat(nested.getProperty("_count"), equalTo(docCount));
    assertThat(nested.getAggregations().asList().isEmpty(), is(false));
    LongTerms values = nested.getAggregations().get("values");
    assertThat(values, notNullValue());
    assertThat(values.getName(), equalTo("values"));
    assertThat(values.getBuckets(), notNullValue());
    assertThat(values.getBuckets().size(), equalTo(uniqueValues));
    for (int i = 0; i < counts.length; ++i) {
        final String key = Long.toString(i);
        if (counts[i] == 0) {
            assertNull(values.getBucketByKey(key));
        } else {
            Bucket bucket = values.getBucketByKey(key);
            assertNotNull(bucket);
            assertEquals(counts[i], bucket.getDocCount());
        }
    }
    assertThat(nested.getProperty("values"), sameInstance(values));
}
Also used : Bucket(org.elasticsearch.search.aggregations.bucket.terms.Terms.Bucket) Nested(org.elasticsearch.search.aggregations.bucket.nested.Nested) LongTerms(org.elasticsearch.search.aggregations.bucket.terms.LongTerms) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Example 3 with LongTerms

use of org.elasticsearch.search.aggregations.bucket.terms.LongTerms in project elasticsearch by elastic.

the class NestedIT method testNestedAsSubAggregation.

public void testNestedAsSubAggregation() throws Exception {
    SearchResponse response = client().prepareSearch("idx").addAggregation(terms("top_values").field("value").size(100).collectMode(aggCollectionMode).subAggregation(nested("nested", "nested").subAggregation(max("max_value").field("nested.value")))).execute().actionGet();
    assertSearchResponse(response);
    LongTerms values = response.getAggregations().get("top_values");
    assertThat(values, notNullValue());
    assertThat(values.getName(), equalTo("top_values"));
    assertThat(values.getBuckets(), notNullValue());
    assertThat(values.getBuckets().size(), equalTo(numParents));
    for (int i = 0; i < numParents; i++) {
        String topValue = "" + (i + 1);
        assertThat(values.getBucketByKey(topValue), notNullValue());
        Nested nested = values.getBucketByKey(topValue).getAggregations().get("nested");
        assertThat(nested, notNullValue());
        Max max = nested.getAggregations().get("max_value");
        assertThat(max, notNullValue());
        assertThat(max.getValue(), equalTo(numChildren[i] == 0 ? Double.NEGATIVE_INFINITY : (double) i + numChildren[i]));
    }
}
Also used : Max(org.elasticsearch.search.aggregations.metrics.max.Max) LongTerms(org.elasticsearch.search.aggregations.bucket.terms.LongTerms) Nested(org.elasticsearch.search.aggregations.bucket.nested.Nested) Matchers.containsString(org.hamcrest.Matchers.containsString) SearchResponse(org.elasticsearch.action.search.SearchResponse) ElasticsearchAssertions.assertSearchResponse(org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)

Aggregations

LongTerms (org.elasticsearch.search.aggregations.bucket.terms.LongTerms)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)2 Nested (org.elasticsearch.search.aggregations.bucket.nested.Nested)2 SearchPlugin (org.elasticsearch.plugins.SearchPlugin)1 AggregationSpec (org.elasticsearch.plugins.SearchPlugin.AggregationSpec)1 PipelineAggregationSpec (org.elasticsearch.plugins.SearchPlugin.PipelineAggregationSpec)1 AdjacencyMatrixAggregationBuilder (org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregationBuilder)1 ChildrenAggregationBuilder (org.elasticsearch.search.aggregations.bucket.children.ChildrenAggregationBuilder)1 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)1 FiltersAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder)1 GeoGridAggregationBuilder (org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder)1 GlobalAggregationBuilder (org.elasticsearch.search.aggregations.bucket.global.GlobalAggregationBuilder)1 DateHistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)1 HistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder)1 MissingAggregationBuilder (org.elasticsearch.search.aggregations.bucket.missing.MissingAggregationBuilder)1 NestedAggregationBuilder (org.elasticsearch.search.aggregations.bucket.nested.NestedAggregationBuilder)1 ReverseNestedAggregationBuilder (org.elasticsearch.search.aggregations.bucket.nested.ReverseNestedAggregationBuilder)1 RangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder)1 DateRangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder)1 GeoDistanceAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.geodistance.GeoDistanceAggregationBuilder)1