use of org.graylog.plugins.views.search.QueryMetadata in project graylog2-server by Graylog2.
the class QueryParserTest method parse.
@Test
public void parse() throws Exception {
final QueryMetadata queryMetadata = queryParser.parse(Query.builder().id("abc123").query(ElasticsearchQueryString.of("user_name:$username$ http_method:$foo$")).timerange(RelativeRange.create(600)).build());
assertThat(queryMetadata.usedParameterNames()).containsExactlyInAnyOrder("username", "foo");
}
use of org.graylog.plugins.views.search.QueryMetadata in project graylog2-server by Graylog2.
the class SearchMetadataResource method metadataForObject.
@POST
@ApiOperation(value = "Metadata for the posted Search object", notes = "Intended for search objects that aren't yet persisted (e.g. for validation or interactive purposes)")
@NoAuditEvent("Only returning metadata for given search, not changing any data")
public SearchMetadata metadataForObject(@ApiParam @NotNull(message = "Search body is mandatory") SearchDTO searchDTO) {
if (searchDTO == null) {
throw new IllegalArgumentException("Search must not be null.");
}
final Search search = searchDTO.toSearch();
final Map<String, QueryMetadata> queryMetadatas = StreamEx.of(search.queries()).toMap(Query::id, query -> queryEngine.parse(search, query));
return SearchMetadata.create(queryMetadatas, Maps.uniqueIndex(search.parameters(), Parameter::name));
}
use of org.graylog.plugins.views.search.QueryMetadata 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