Search in sources :

Example 1 with QueryMetadata

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");
}
Also used : QueryMetadata(org.graylog.plugins.views.search.QueryMetadata) Test(org.junit.Test)

Example 2 with QueryMetadata

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));
}
Also used : QueryMetadata(org.graylog.plugins.views.search.QueryMetadata) Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) POST(javax.ws.rs.POST) ApiOperation(io.swagger.annotations.ApiOperation) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent)

Example 3 with QueryMetadata

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");
}
Also used : QueryMetadata(org.graylog.plugins.views.search.QueryMetadata) SearchType(org.graylog.plugins.views.search.SearchType) Test(org.junit.Test)

Aggregations

QueryMetadata (org.graylog.plugins.views.search.QueryMetadata)3 Test (org.junit.Test)2 ApiOperation (io.swagger.annotations.ApiOperation)1 POST (javax.ws.rs.POST)1 Query (org.graylog.plugins.views.search.Query)1 Search (org.graylog.plugins.views.search.Search)1 SearchType (org.graylog.plugins.views.search.SearchType)1 NoAuditEvent (org.graylog2.audit.jersey.NoAuditEvent)1