use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.
the class QueryTest method testFullQueryWithType.
/**
* Test that json parser recognizes full query with its type and query string value as an object (backwards compatibility)
*/
@Test
public void testFullQueryWithType() throws IOException {
final Query query = objectMapper.readValue(getClass().getResourceAsStream("/org/graylog/plugins/views/search/query/full-query.json"), Query.class);
final ElasticsearchQueryString queryString = (ElasticsearchQueryString) query.query();
assertThat(queryString.queryString()).isEqualTo("some-full-query");
}
use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.
the class QueryTest method testSimpleQuery.
/**
* Test that json parser recognizes query that's just a string, not object
*/
@Test
public void testSimpleQuery() throws IOException {
final Query query = objectMapper.readValue(getClass().getResourceAsStream("/org/graylog/plugins/views/search/query/simple-query.json"), Query.class);
final ElasticsearchQueryString queryString = (ElasticsearchQueryString) query.query();
assertThat(queryString.queryString()).isEqualTo("some-simple-query");
}
use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.
the class AggregationEventProcessor method sourceMessagesForEvent.
@Override
public void sourceMessagesForEvent(Event event, Consumer<List<MessageSummary>> messageConsumer, long limit) throws EventProcessorException {
if (config.series().isEmpty()) {
if (limit <= 0) {
return;
}
final EventOriginContext.ESEventOriginContext esContext = EventOriginContext.parseESContext(event.getOriginContext()).orElseThrow(() -> new EventProcessorException("Failed to parse origin context", false, eventDefinition));
try {
final ResultMessage message;
message = messages.get(esContext.messageId(), esContext.indexName());
messageConsumer.accept(Lists.newArrayList(new MessageSummary(message.getIndex(), message.getMessage())));
} catch (IOException e) {
throw new EventProcessorException("Failed to query origin context message", false, eventDefinition, e);
}
} else {
final AtomicLong msgCount = new AtomicLong(0L);
final MoreSearch.ScrollCallback callback = (messages, continueScrolling) -> {
final List<MessageSummary> summaries = Lists.newArrayList();
for (final ResultMessage resultMessage : messages) {
if (msgCount.incrementAndGet() > limit) {
continueScrolling.set(false);
break;
}
final Message msg = resultMessage.getMessage();
summaries.add(new MessageSummary(resultMessage.getIndex(), msg));
}
messageConsumer.accept(summaries);
};
ElasticsearchQueryString scrollQueryString = ElasticsearchQueryString.of(config.query());
scrollQueryString = scrollQueryString.concatenate(groupByQueryString(event));
LOG.debug("scrollQueryString: {}", scrollQueryString);
final TimeRange timeRange = AbsoluteRange.create(event.getTimerangeStart(), event.getTimerangeEnd());
moreSearch.scrollQuery(scrollQueryString.queryString(), config.streams(), config.queryParameters(), timeRange, Math.min(500, Ints.saturatedCast(limit)), callback);
}
}
use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.
the class CommandFactory method decorateQueryString.
private ElasticsearchQueryString decorateQueryString(Search search, Query query, ElasticsearchQueryString undecorated) {
String queryString = undecorated.queryString();
String decorated = queryStringDecorator.decorateQueryString(queryString, search, query);
return ElasticsearchQueryString.of(decorated);
}
use of org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString in project graylog2-server by Graylog2.
the class QueryParser method parse.
public QueryMetadata parse(Query query) {
checkArgument(query.query() instanceof ElasticsearchQueryString);
final String mainQueryString = query.query().queryString();
final java.util.stream.Stream<String> queryStringStreams = java.util.stream.Stream.concat(java.util.stream.Stream.of(mainQueryString), query.searchTypes().stream().flatMap(this::queryStringsFromSearchType));
return queryStringStreams.map(queryStringParser::parse).reduce(QueryMetadata.builder().build(), (meta1, meta2) -> QueryMetadata.builder().usedParameterNames(Sets.union(meta1.usedParameterNames(), meta2.usedParameterNames())).build());
}
Aggregations