Search in sources :

Example 1 with Cardinality

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Cardinality in project graylog2-server by Graylog2.

the class ESCardinalityHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Cardinality cardinalitySpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
    final CardinalityAggregationBuilder card = AggregationBuilders.cardinality(name).field(cardinalitySpec.field());
    record(queryContext, pivot, cardinalitySpec, name, org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Cardinality.class);
    return Optional.of(card);
}
Also used : CardinalityAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.CardinalityAggregationBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with Cardinality

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Cardinality in project graylog2-server by Graylog2.

the class SearchesAdapterES7 method fieldStats.

@Override
public FieldStatsResult fieldStats(String query, String filter, TimeRange range, Set<String> indices, String field, boolean includeCardinality, boolean includeStats, boolean includeCount) {
    final SearchesConfig config = SearchesConfig.builder().query(query).filter(filter).range(range).offset(0).limit(-1).build();
    final SearchSourceBuilder searchSourceBuilder = searchRequestFactory.create(config);
    if (includeCount) {
        searchSourceBuilder.aggregation(AggregationBuilders.count(AGG_VALUE_COUNT).field(field));
    }
    if (includeStats) {
        searchSourceBuilder.aggregation(AggregationBuilders.extendedStats(AGG_EXTENDED_STATS).field(field));
    }
    if (includeCardinality) {
        searchSourceBuilder.aggregation(AggregationBuilders.cardinality(AGG_CARDINALITY).field(field));
    }
    if (indices.isEmpty()) {
        return FieldStatsResult.empty(query, searchSourceBuilder.toString());
    }
    final SearchRequest searchRequest = new SearchRequest(indices.toArray(new String[0])).source(searchSourceBuilder);
    final SearchResponse searchResult = client.search(searchRequest, "Unable to retrieve fields stats");
    final List<ResultMessage> resultMessages = extractResultMessages(searchResult);
    final long tookMs = searchResult.getTook().getMillis();
    final ExtendedStats extendedStatsAggregation = searchResult.getAggregations().get(AGG_EXTENDED_STATS);
    final ValueCount valueCountAggregation = searchResult.getAggregations().get(AGG_VALUE_COUNT);
    final Cardinality cardinalityAggregation = searchResult.getAggregations().get(AGG_CARDINALITY);
    return createFieldStatsResult(extendedStatsAggregation, valueCountAggregation, cardinalityAggregation, resultMessages, query, searchSourceBuilder.toString(), tookMs);
}
Also used : SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) ValueCount(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ValueCount) SearchesConfig(org.graylog2.indexer.searches.SearchesConfig) Cardinality(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Cardinality) ExtendedStats(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ExtendedStats) ResultMessage(org.graylog2.indexer.results.ResultMessage) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)

Example 3 with Cardinality

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Cardinality in project graylog2-server by Graylog2.

the class TestMultisearchResponse method getDefaultNamedXContents.

private static List<NamedXContentRegistry.Entry> getDefaultNamedXContents() {
    Map<String, ContextParser<Object, ? extends Aggregation>> map = new HashMap<>();
    map.put("cardinality", (p, c) -> ParsedCardinality.fromXContent(p, (String) c));
    map.put("percentiles_bucket", (p, c) -> ParsedPercentilesBucket.fromXContent(p, (String) c));
    map.put("median_absolute_deviation", (p, c) -> ParsedMedianAbsoluteDeviation.fromXContent(p, (String) c));
    map.put("min", (p, c) -> ParsedMin.fromXContent(p, (String) c));
    map.put("max", (p, c) -> ParsedMax.fromXContent(p, (String) c));
    map.put("sum", (p, c) -> ParsedSum.fromXContent(p, (String) c));
    map.put("avg", (p, c) -> ParsedAvg.fromXContent(p, (String) c));
    map.put("weighted_avg", (p, c) -> ParsedWeightedAvg.fromXContent(p, (String) c));
    map.put("value_count", (p, c) -> ParsedValueCount.fromXContent(p, (String) c));
    map.put("simple_value", (p, c) -> ParsedSimpleValue.fromXContent(p, (String) c));
    map.put("derivative", (p, c) -> ParsedDerivative.fromXContent(p, (String) c));
    map.put("bucket_metric_value", (p, c) -> ParsedBucketMetricValue.fromXContent(p, (String) c));
    map.put("stats", (p, c) -> ParsedStats.fromXContent(p, (String) c));
    map.put("stats_bucket", (p, c) -> ParsedStatsBucket.fromXContent(p, (String) c));
    map.put("extended_stats", (p, c) -> ParsedExtendedStats.fromXContent(p, (String) c));
    map.put("extended_stats_bucket", (p, c) -> ParsedExtendedStatsBucket.fromXContent(p, (String) c));
    map.put("histogram", (p, c) -> ParsedHistogram.fromXContent(p, (String) c));
    map.put("date_histogram", (p, c) -> ParsedDateHistogram.fromXContent(p, (String) c));
    map.put("auto_date_histogram", (p, c) -> ParsedAutoDateHistogram.fromXContent(p, (String) c));
    map.put("sterms", (p, c) -> ParsedStringTerms.fromXContent(p, (String) c));
    map.put("lterms", (p, c) -> ParsedLongTerms.fromXContent(p, (String) c));
    map.put("dterms", (p, c) -> ParsedDoubleTerms.fromXContent(p, (String) c));
    map.put("missing", (p, c) -> ParsedMissing.fromXContent(p, (String) c));
    map.put("nested", (p, c) -> ParsedNested.fromXContent(p, (String) c));
    map.put("reverse_nested", (p, c) -> ParsedReverseNested.fromXContent(p, (String) c));
    map.put("global", (p, c) -> ParsedGlobal.fromXContent(p, (String) c));
    map.put("filter", (p, c) -> ParsedFilter.fromXContent(p, (String) c));
    map.put("sampler", (p, c) -> ParsedSampler.fromXContent(p, (String) c));
    map.put("range", (p, c) -> ParsedRange.fromXContent(p, (String) c));
    map.put("date_range", (p, c) -> ParsedDateRange.fromXContent(p, (String) c));
    map.put("filters", (p, c) -> ParsedFilters.fromXContent(p, (String) c));
    map.put("top_hits", (p, c) -> ParsedTopHits.fromXContent(p, (String) c));
    map.put("composite", (p, c) -> ParsedComposite.fromXContent(p, (String) c));
    List<NamedXContentRegistry.Entry> entries = map.entrySet().stream().map((entry) -> new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())).collect(Collectors.toList());
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("term"), (parser, context) -> TermSuggestion.fromXContent(parser, (String) context)));
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("phrase"), (parser, context) -> PhraseSuggestion.fromXContent(parser, (String) context)));
    entries.add(new NamedXContentRegistry.Entry(Suggest.Suggestion.class, new ParseField("completion"), (parser, context) -> CompletionSuggestion.fromXContent(parser, (String) context)));
    return entries;
}
Also used : Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) ParsedDateHistogram(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.ParsedDateHistogram) ParsedDateRange(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.range.ParsedDateRange) URL(java.net.URL) ParsedAvg(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedAvg) ParsedMin(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedMin) ParsedSimpleValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedSimpleValue) URISyntaxException(java.net.URISyntaxException) ParsedPercentilesBucket(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedPercentilesBucket) TermSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.term.TermSuggestion) ParsedRange(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.range.ParsedRange) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) Map(java.util.Map) ParsedValueCount(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedValueCount) Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) ParsedCardinality(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedCardinality) Path(java.nio.file.Path) ParsedSum(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedSum) ParsedNested(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.nested.ParsedNested) ParsedStringTerms(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.ParsedStringTerms) ContextParser(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.ContextParser) ParsedFilters(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.ParsedFilters) ParseField(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.ParseField) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) CompletionSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.completion.CompletionSuggestion) ParsedAutoDateHistogram(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.ParsedAutoDateHistogram) ParsedMax(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedMax) NamedXContentRegistry(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.NamedXContentRegistry) ParsedDerivative(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedDerivative) ParsedReverseNested(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.nested.ParsedReverseNested) ParsedMedianAbsoluteDeviation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedMedianAbsoluteDeviation) ParsedStats(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedStats) ParsedSampler(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.sampler.ParsedSampler) ParsedFilter(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.filter.ParsedFilter) PhraseSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.phrase.PhraseSuggestion) Suggest(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.Suggest) JsonXContent(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.json.JsonXContent) ParsedBucketMetricValue(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedBucketMetricValue) HashMap(java.util.HashMap) ParsedExtendedStatsBucket(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedExtendedStatsBucket) ParsedStatsBucket(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.pipeline.ParsedStatsBucket) LoggingDeprecationHandler(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.LoggingDeprecationHandler) ParsedWeightedAvg(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedWeightedAvg) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) IOException(java.io.IOException) ParsedLongTerms(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.ParsedLongTerms) ParsedMissing(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.missing.ParsedMissing) XContentParser(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.XContentParser) ParsedTopHits(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedTopHits) ParsedExtendedStats(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ParsedExtendedStats) Paths(java.nio.file.Paths) ParsedHistogram(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.ParsedHistogram) ParsedGlobal(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.global.ParsedGlobal) ParsedDoubleTerms(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.ParsedDoubleTerms) ParsedComposite(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.composite.ParsedComposite) InputStream(java.io.InputStream) TermSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.term.TermSuggestion) CompletionSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.completion.CompletionSuggestion) PhraseSuggestion(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.suggest.phrase.PhraseSuggestion) ContextParser(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.ContextParser) HashMap(java.util.HashMap) NamedXContentRegistry(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.NamedXContentRegistry) ParseField(org.graylog.shaded.elasticsearch7.org.elasticsearch.common.ParseField)

Aggregations

Resources (com.google.common.io.Resources)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UncheckedIOException (java.io.UncheckedIOException)1 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)1 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)1 SearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)1 ParseField (org.graylog.shaded.elasticsearch7.org.elasticsearch.common.ParseField)1 ContextParser (org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.ContextParser)1 LoggingDeprecationHandler (org.graylog.shaded.elasticsearch7.org.elasticsearch.common.xcontent.LoggingDeprecationHandler)1