Search in sources :

Example 1 with ScrollCommand

use of org.graylog2.indexer.searches.ScrollCommand in project graylog2-server by Graylog2.

the class SearchesAdapterES6 method applySortingIfPresent.

private void applySortingIfPresent(SearchSourceBuilder searchSourceBuilder, ScrollCommand scrollCommand) {
    final Sorting sort = scrollCommand.sorting().orElse(DEFAULT_SORTING);
    searchSourceBuilder.sort(sort.getField(), sortOrderMapper.fromSorting(sort));
}
Also used : Sorting(org.graylog2.indexer.searches.Sorting)

Example 2 with ScrollCommand

use of org.graylog2.indexer.searches.ScrollCommand in project graylog2-server by Graylog2.

the class MoreSearchAdapterES7 method scrollEvents.

@Override
public void scrollEvents(String queryString, TimeRange timeRange, Set<String> affectedIndices, Set<String> streams, String scrollTime, int batchSize, ScrollEventsCallback resultCallback) throws EventProcessorException {
    final ScrollCommand scrollCommand = buildScrollCommand(queryString, timeRange, affectedIndices, streams, batchSize);
    final ScrollResult scrollResult = scroll.scroll(scrollCommand);
    final AtomicBoolean continueScrolling = new AtomicBoolean(true);
    final Stopwatch stopwatch = Stopwatch.createStarted();
    try {
        ScrollResult.ScrollChunk scrollChunk = scrollResult.nextChunk();
        while (continueScrolling.get() && scrollChunk != null) {
            final List<ResultMessage> messages = scrollChunk.getMessages();
            LOG.debug("Passing <{}> messages to callback", messages.size());
            resultCallback.accept(Collections.unmodifiableList(messages), continueScrolling);
            // Stop if the resultCallback told us to stop
            if (!continueScrolling.get()) {
                break;
            }
            scrollChunk = scrollResult.nextChunk();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        try {
            // Tell Elasticsearch that we are done with the scroll so it can release resources as soon as possible
            // instead of waiting for the scroll timeout to kick in.
            scrollResult.cancel();
        } catch (Exception ignored) {
        }
        LOG.debug("Scrolling done - took {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS));
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScrollResult(org.graylog2.indexer.results.ScrollResult) ScrollCommand(org.graylog2.indexer.searches.ScrollCommand) Stopwatch(com.google.common.base.Stopwatch) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) ResultMessage(org.graylog2.indexer.results.ResultMessage) EventProcessorException(org.graylog.events.processor.EventProcessorException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Aggregations

Stopwatch (com.google.common.base.Stopwatch)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 EventProcessorException (org.graylog.events.processor.EventProcessorException)1 ResultMessage (org.graylog2.indexer.results.ResultMessage)1 ScrollResult (org.graylog2.indexer.results.ScrollResult)1 ScrollCommand (org.graylog2.indexer.searches.ScrollCommand)1 Sorting (org.graylog2.indexer.searches.Sorting)1