use of org.graylog.plugins.views.search.SearchType in project graylog2-server by Graylog2.
the class PivotAggregationSearch method getSourceStreamsQuery.
/**
* Returns the query to compute the sources streams for the aggregation.
*
* @param parameters processor parameters
* @return source streams query
*/
private Query getSourceStreamsQuery(AggregationEventProcessorParameters parameters) {
final Pivot pivot = Pivot.builder().id(STREAMS_PIVOT_ID).rollup(true).rowGroups(ImmutableList.of(Values.builder().limit(Integer.MAX_VALUE).field("streams").build())).series(ImmutableList.of(Count.builder().id(STREAMS_PIVOT_COUNT_ID).build())).build();
final Set<SearchType> searchTypes = Collections.singleton(pivot);
final Query.Builder queryBuilder = Query.builder().id(STREAMS_QUERY_ID).searchTypes(searchTypes).query(ElasticsearchQueryString.of(config.query())).timerange(parameters.timerange());
final Set<String> streams = getStreams(parameters);
if (!streams.isEmpty()) {
queryBuilder.filter(filteringForStreamIds(streams));
}
return queryBuilder.build();
}
use of org.graylog.plugins.views.search.SearchType in project graylog2-server by Graylog2.
the class ViewsResource method validateIntegrity.
private void validateIntegrity(ViewDTO dto, SearchUser searchUser) {
final Search search = searchDomain.getForUser(dto.searchId(), searchUser).orElseThrow(() -> new BadRequestException("Search " + dto.searchId() + " not available"));
final Set<String> searchQueries = search.queries().stream().map(Query::id).collect(Collectors.toSet());
final Set<String> stateQueries = dto.state().keySet();
if (!searchQueries.containsAll(stateQueries)) {
final Sets.SetView<String> diff = Sets.difference(searchQueries, stateQueries);
throw new BadRequestException("Search queries do not correspond to view/state queries, missing query IDs: " + diff);
}
final Set<String> searchTypes = search.queries().stream().flatMap(q -> q.searchTypes().stream()).map(SearchType::id).collect(Collectors.toSet());
final Set<String> stateTypes = dto.state().values().stream().flatMap(v -> v.widgetMapping().values().stream()).flatMap(Collection::stream).collect(Collectors.toSet());
if (!searchTypes.containsAll(stateTypes)) {
final Sets.SetView<String> diff = Sets.difference(searchTypes, stateTypes);
throw new BadRequestException("Search types do not correspond to view/search types, missing searches: " + diff);
}
final Set<String> widgetIds = dto.state().values().stream().flatMap(v -> v.widgets().stream()).map(WidgetDTO::id).collect(Collectors.toSet());
final Set<String> widgetPositions = dto.state().values().stream().flatMap(v -> v.widgetPositions().keySet().stream()).collect(Collectors.toSet());
if (!widgetPositions.containsAll(widgetIds)) {
final Sets.SetView<String> diff = Sets.difference(widgetPositions, widgetIds);
throw new BadRequestException("Widget positions don't correspond to widgets, missing widget possitions: " + diff);
}
}
use of org.graylog.plugins.views.search.SearchType in project graylog2-server by Graylog2.
the class CommandFactory method buildWithMessageList.
public ExportMessagesCommand buildWithMessageList(Search search, String messageListId, ResultFormat resultFormat) {
Query query = search.queryForSearchType(messageListId);
SearchType searchType = searchTypeFrom(query, messageListId);
final List<Decorator> decorators = searchType instanceof MessageList ? ((MessageList) searchType).decorators() : Collections.emptyList();
ExportMessagesCommand.Builder commandBuilder = builderFrom(resultFormat).timeRange(resultFormat.timerange().orElse(toAbsolute(timeRangeFrom(query, searchType)))).queryString(queryStringFrom(search, query, searchType)).streams(streamsFrom(query, searchType)).decorators(decorators);
return commandBuilder.build();
}
use of org.graylog.plugins.views.search.SearchType in project graylog2-server by Graylog2.
the class SearchResource method createSearch.
protected Search createSearch(String queryString, int limit, String filter, List<String> fieldList, Sort sorting, TimeRange timeRange) {
final SearchType searchType = createMessageList(sorting, limit, fieldList);
final Query query = Query.builder().query(ElasticsearchQueryString.of(queryString)).filter(QueryStringFilter.builder().query(Strings.isNullOrEmpty(filter) ? "*" : filter).build()).timerange(timeRange).searchTypes(Collections.singleton(searchType)).build();
return Search.Builder.create().queries(ImmutableSet.of(query)).build();
}
use of org.graylog.plugins.views.search.SearchType in project graylog2-server by Graylog2.
the class QueryParserTest method parseAlsoConsidersWidgetFilters.
@Test
public void parseAlsoConsidersWidgetFilters() throws Exception {
final SearchType searchType1 = Pivot.builder().id("searchType1").filter(QueryStringFilter.builder().query("source:$bar$").build()).series(new ArrayList<>()).rollup(false).build();
final SearchType searchType2 = Pivot.builder().id("searchType2").filter(AndFilter.builder().filters(ImmutableSet.of(QueryStringFilter.builder().query("http_action:$baz$").build(), QueryStringFilter.builder().query("source:localhost").build())).build()).series(new ArrayList<>()).rollup(false).build();
final QueryMetadata queryMetadata = queryParser.parse(Query.builder().id("abc123").query(ElasticsearchQueryString.of("user_name:$username$ http_method:$foo$")).timerange(RelativeRange.create(600)).searchTypes(ImmutableSet.of(searchType1, searchType2)).build());
assertThat(queryMetadata.usedParameterNames()).containsExactlyInAnyOrder("username", "foo", "bar", "baz");
}
Aggregations