use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.ExtendedStats 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);
}
Aggregations