use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project graylog2-server by Graylog2.
the class ESMessageList method applyHighlightingIfActivated.
private void applyHighlightingIfActivated(SearchSourceBuilder searchSourceBuilder, SearchJob job, Query query) {
if (!allowHighlighting) {
return;
}
final QueryStringQueryBuilder highlightQuery = decoratedHighlightQuery(job, query);
searchSourceBuilder.highlighter(new HighlightBuilder().requireFieldMatch(false).highlightQuery(highlightQuery).field("*").fragmentSize(0).numOfFragments(0));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder 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));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project graylog2-server by Graylog2.
the class SearchesAdapterES7 method count.
@Override
public CountResult count(Set<String> affectedIndices, String query, TimeRange range, String filter) {
final SearchesConfig config = SearchesConfig.builder().query(query).range(range).filter(filter).limit(0).offset(0).build();
final SearchSourceBuilder searchSourceBuilder = searchRequestFactory.create(config);
final SearchRequest searchRequest = new SearchRequest(affectedIndices.toArray(new String[0])).source(searchSourceBuilder);
final SearchResponse result = client.search(searchRequest, "Fetching message count failed for indices ");
return CountResult.create(result.getHits().getTotalHits().value, result.getTook().getMillis());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project graylog2-server by Graylog2.
the class ElasticsearchExportBackend method searchSourceBuilderFrom.
private SearchSourceBuilder searchSourceBuilderFrom(ExportMessagesCommand command) {
QueryBuilder query = queryFrom(command);
SearchSourceBuilder ssb = new SearchSourceBuilder().query(query).size(command.chunkSize()).sort(Message.FIELD_TIMESTAMP, SortOrder.ASC);
return requestStrategy.configure(ssb);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder in project graylog2-server by Graylog2.
the class QuerySuggestionsES6 method suggest.
@Override
public SuggestionResponse suggest(SuggestionRequest req) {
final Set<String> affectedIndices = indexLookup.indexNamesForStreamsInTimeRange(req.streams(), req.timerange());
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", SuggestBuilders.termSuggestion(req.field()).text(req.input()).size(req.size())));
final Search.Builder searchBuilder = new Search.Builder(search.toString()).addType(IndexMapping.TYPE_MESSAGE).addIndex(affectedIndices.isEmpty() ? Collections.singleton("") : affectedIndices).allowNoIndices(false).ignoreUnavailable(false);
try {
final SearchResult result = JestUtils.execute(jestClient, searchBuilder.build(), () -> "Unable to perform aggregation: ");
final TermsAggregation aggregation = result.getAggregations().getTermsAggregation("fieldvalues");
final List<SuggestionEntry> entries = aggregation.getBuckets().stream().map(b -> new SuggestionEntry(b.getKeyAsString(), b.getCount())).collect(Collectors.toList());
if (!entries.isEmpty()) {
return SuggestionResponse.forSuggestions(req.field(), req.input(), entries, aggregation.getSumOtherDocCount());
} else {
final List<SuggestionEntry> corrections = Optional.of(result.getJsonObject()).map(o -> o.get("suggest")).map(o -> o.get("corrections")).map(o -> o.get(0)).map(o -> o.get("options")).map(options -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(options.elements(), Spliterator.ORDERED), false).map(option -> new SuggestionEntry(option.get("text").textValue(), option.get("freq").longValue())).collect(Collectors.toList())).orElseGet(Collections::emptyList);
return SuggestionResponse.forSuggestions(req.field(), req.input(), corrections, null);
}
} catch (Exception e) {
final SuggestionError err = SuggestionError.create(e.getClass().getSimpleName(), e.getMessage());
return SuggestionResponse.forError(req.field(), req.input(), err);
}
}
Aggregations