use of org.graylog2.indexer.indices.Indices 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);
}
use of org.graylog2.indexer.indices.Indices in project graylog2-server by Graylog2.
the class MoreSearch method getAffectedIndices.
private Set<String> getAffectedIndices(Set<String> streamIds, TimeRange timeRange) {
final SortedSet<IndexRange> indexRanges = indexRangeService.find(timeRange.getFrom(), timeRange.getTo());
// We support an empty streams list and return all affected indices in that case.
if (streamIds.isEmpty()) {
return indexRanges.stream().map(IndexRange::indexName).collect(Collectors.toSet());
} else {
final Set<Stream> streams = loadStreams(streamIds);
final IndexRangeContainsOneOfStreams indexRangeContainsOneOfStreams = new IndexRangeContainsOneOfStreams(streams);
return indexRanges.stream().filter(indexRangeContainsOneOfStreams).map(IndexRange::indexName).collect(Collectors.toSet());
}
}
Aggregations