use of org.graylog2.indexer.searches.SearchesConfig in project graylog2-server by Graylog2.
the class Searches method search.
public SearchResult search(SearchesConfig config) {
final Set<IndexRange> indexRanges = determineAffectedIndicesWithRanges(config.range(), config.filter());
final Set<String> indices = extractIndexNamesFromIndexRanges(indexRanges);
final SearchResult result = searchesAdapter.search(indices, indexRanges, config);
recordEsMetrics(result.tookMs(), config.range());
return result;
}
use of org.graylog2.indexer.searches.SearchesConfig in project graylog2-server by Graylog2.
the class SearchesAdapterES6 method search.
@Override
public SearchResult search(Set<String> indices, Set<IndexRange> indexRanges, SearchesConfig config) {
final SearchSourceBuilder requestBuilder = searchRequest(config);
if (indexRanges.isEmpty()) {
return SearchResult.empty(config.query(), requestBuilder.toString());
}
final Search.Builder searchBuilder = new Search.Builder(requestBuilder.toString()).addType(IndexMapping.TYPE_MESSAGE).addIndex(indices);
final io.searchbox.core.SearchResult searchResult = multiSearch.wrap(searchBuilder.build(), () -> "Unable to perform search query");
final List<ResultMessage> hits = searchResult.getHits(Map.class, false).stream().map(hit -> ResultMessage.parseFromSource(hit.id, hit.index, (Map<String, Object>) hit.source, hit.highlight)).collect(Collectors.toList());
return new SearchResult(hits, searchResult.getTotal(), indexRanges, config.query(), requestBuilder.toString(), multiSearch.tookMsFromSearchResult(searchResult));
}
use of org.graylog2.indexer.searches.SearchesConfig in project graylog2-server by Graylog2.
the class SearchesAdapterES7 method search.
@Override
public SearchResult search(Set<String> indices, Set<IndexRange> indexRanges, SearchesConfig config) {
final SearchSourceBuilder searchSourceBuilder = searchRequestFactory.create(config);
if (indexRanges.isEmpty()) {
return SearchResult.empty(config.query(), searchSourceBuilder.toString());
}
final SearchRequest searchRequest = new SearchRequest(indices.toArray(new String[0])).source(searchSourceBuilder);
final SearchResponse searchResult = client.search(searchRequest, "Unable to perform search query");
final List<ResultMessage> resultMessages = extractResultMessages(searchResult);
final long totalResults = searchResult.getHits().getTotalHits().value;
final long tookMs = searchResult.getTook().getMillis();
final String builtQuery = searchSourceBuilder.toString();
return new SearchResult(resultMessages, totalResults, indexRanges, config.query(), builtQuery, tookMs);
}
use of org.graylog2.indexer.searches.SearchesConfig 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