use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class ElasticsearchClient method msearch.
public List<MultiSearchResponse.Item> msearch(List<SearchRequest> searchRequests, String errorMessage) {
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
searchRequests.forEach(multiSearchRequest::add);
final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
return Streams.stream(result).collect(Collectors.toList());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class ElasticsearchClient method search.
public SearchResponse search(SearchRequest searchRequest, String errorMessage) {
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest().add(searchRequest);
final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
return firstResponseFrom(result, errorMessage);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class QuerySuggestionsES7 method suggest.
@Override
public SuggestionResponse suggest(SuggestionRequest req) {
final Set<String> affectedIndices = indexLookup.indexNamesForStreamsInTimeRange(req.streams(), req.timerange());
final TermSuggestionBuilder suggestionBuilder = SuggestBuilders.termSuggestion(req.field()).text(req.input()).size(req.size());
final SearchSourceBuilder search = new SearchSourceBuilder().query(QueryBuilders.prefixQuery(req.field(), req.input())).size(0).aggregation(AggregationBuilders.terms("fieldvalues").field(req.field()).size(req.size())).suggest(new SuggestBuilder().addSuggestion("corrections", suggestionBuilder));
try {
final SearchResponse result = client.singleSearch(new SearchRequest(affectedIndices.toArray(new String[] {})).source(search), "Failed to execute aggregation");
final ParsedStringTerms fieldValues = result.getAggregations().get("fieldvalues");
final List<SuggestionEntry> entries = fieldValues.getBuckets().stream().map(b -> new SuggestionEntry(b.getKeyAsString(), b.getDocCount())).collect(Collectors.toList());
if (!entries.isEmpty()) {
return SuggestionResponse.forSuggestions(req.field(), req.input(), entries, fieldValues.getSumOfOtherDocCounts());
} else {
TermSuggestion suggestion = result.getSuggest().getSuggestion("corrections");
final List<SuggestionEntry> corrections = suggestion.getEntries().stream().flatMap(e -> e.getOptions().stream()).map(o -> new SuggestionEntry(o.getText().string(), o.getFreq())).collect(Collectors.toList());
return SuggestionResponse.forSuggestions(req.field(), req.input(), corrections, null);
}
} catch (org.graylog.shaded.elasticsearch7.org.elasticsearch.ElasticsearchException exception) {
final SuggestionError err = tryResponseException(exception).orElseGet(() -> parseException(exception));
return SuggestionResponse.forError(req.field(), req.input(), err);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class SearchAfter method nextChunk.
@Override
public List<SearchHit> nextChunk(SearchRequest search, ExportMessagesCommand command) {
SearchResponse result = search(search);
List<SearchHit> hits = Streams.stream(result.getHits()).collect(Collectors.toList());
searchAfterValues = lastHitSortFrom(hits);
return hits;
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project graylog2-server by Graylog2.
the class Scroll method scroll.
public ScrollResult scroll(ScrollCommand scrollCommand) {
final SearchSourceBuilder searchQuery = searchRequestFactory.create(scrollCommand);
searchQuery.fetchSource(scrollCommand.fields().toArray(new String[0]), new String[0]);
scrollCommand.batchSize().ifPresent(batchSize -> searchQuery.size(Math.toIntExact(batchSize)));
final SearchRequest request = scrollBuilder(searchQuery, scrollCommand.indices());
final SearchResponse result = client.singleSearch(request, "Unable to perform scroll search");
return scrollResultFactory.create(result, searchQuery.toString(), DEFAULT_SCROLLTIME, scrollCommand.fields(), scrollCommand.limit().orElse(-1));
}
Aggregations