Search in sources :

Example 16 with Searches

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

the class SearchesIT method searchDoesNotIncludeJestMetadata.

@Test
public void searchDoesNotIncludeJestMetadata() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
    final SearchResult searchResult = searches.search("_id:1", range, 0, 0, Sorting.DEFAULT);
    assertThat(searchResult).isNotNull();
    assertThat(searchResult.getTotalResults()).isEqualTo(1L);
    assertThat(searchResult.getFields()).doesNotContain("es_metadata_id", "es_metadata_version");
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) SearchResult(org.graylog2.indexer.results.SearchResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 17 with Searches

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

the class SearchesIT method fieldStatsDoesNotIncludeJestMetadata.

@Test
public void fieldStatsDoesNotIncludeJestMetadata() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
    final FieldStatsResult fieldStatsResult = searches.fieldStats("n", "_id:1", range);
    assertThat(fieldStatsResult).isNotNull();
    assertThat(fieldStatsResult.searchHits()).isNotNull();
    assertThat(fieldStatsResult.searchHits()).hasSize(1);
    final ResultMessage resultMessage = fieldStatsResult.searchHits().get(0);
    assertThat(resultMessage.getMessage().getFields()).doesNotContainKeys("es_metadata_id", "es_metadata_version");
}
Also used : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) ResultMessage(org.graylog2.indexer.results.ResultMessage) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 18 with Searches

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

the class SearchesIT method testFieldStats.

@Test
public void testFieldStats() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    FieldStatsResult fieldStats = searches.fieldStats("n", "*", AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC)));
    assertThat(fieldStats).satisfies(result -> {
        assertThat(result.searchHits()).hasSize(10);
        assertThat(result.count()).isEqualTo(8);
        assertThat(result.min()).isEqualTo(1.0);
        assertThat(result.max()).isEqualTo(4.0);
        assertThat(result.mean()).isEqualTo(2.375);
        assertThat(result.sum()).isEqualTo(19.0);
        assertThat(result.sumOfSquares()).isEqualTo(53.0);
        assertThat(result.variance()).isEqualTo(0.984375);
        assertThat(result.stdDeviation()).isEqualTo(0.9921567416492215);
    });
}
Also used : FieldStatsResult(org.graylog2.indexer.results.FieldStatsResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 19 with Searches

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

the class SearchesIT method searchReturnsResultWithSelectiveFields.

@Test
public void searchReturnsResultWithSelectiveFields() throws Exception {
    importFixture("org/graylog2/indexer/searches/SearchesIT.json");
    final AbsoluteRange range = AbsoluteRange.create(new DateTime(2015, 1, 1, 0, 0, DateTimeZone.UTC).withZone(UTC), new DateTime(2015, 1, 2, 0, 0, DateTimeZone.UTC).withZone(UTC));
    final SearchesConfig searchesConfig = SearchesConfig.builder().query("*").range(range).limit(1).offset(0).fields(Collections.singletonList("source")).build();
    final SearchResult searchResult = searches.search(searchesConfig);
    assertThat(searchResult).isNotNull();
    assertThat(searchResult.getResults()).hasSize(1);
    assertThat(searchResult.getTotalResults()).isEqualTo(10L);
}
Also used : AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) SearchResult(org.graylog2.indexer.results.SearchResult) ZonedDateTime(java.time.ZonedDateTime) DateTime(org.joda.time.DateTime) ElasticsearchBaseTest(org.graylog.testing.elasticsearch.ElasticsearchBaseTest) Test(org.junit.Test)

Example 20 with Searches

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

the class SavedSearchesResource method views.

@GET
@ApiOperation("Get a list of all searches")
public PaginatedResponse<ViewSummaryDTO> views(@ApiParam(name = "page") @QueryParam("page") @DefaultValue("1") int page, @ApiParam(name = "per_page") @QueryParam("per_page") @DefaultValue("50") int perPage, @ApiParam(name = "sort", value = "The field to sort the result on", required = true, allowableValues = "id,title,created_at") @DefaultValue(ViewDTO.FIELD_TITLE) @QueryParam("sort") String sortField, @ApiParam(name = "order", value = "The sort direction", allowableValues = "asc, desc") @DefaultValue("asc") @QueryParam("order") String order, @ApiParam(name = "query") @QueryParam("query") String query, @Context SearchUser searchUser) {
    if (!ViewDTO.SORT_FIELDS.contains(sortField.toLowerCase(ENGLISH))) {
        sortField = ViewDTO.FIELD_TITLE;
    }
    try {
        final SearchQuery searchQuery = searchQueryParser.parse(query);
        final PaginatedList<ViewSummaryDTO> result = dbService.searchSummariesPaginatedByType(ViewDTO.Type.SEARCH, searchQuery, searchUser::canReadView, order, sortField, page, perPage);
        return PaginatedResponse.create("views", result, query);
    } catch (IllegalArgumentException e) {
        throw new BadRequestException(e.getMessage(), e);
    }
}
Also used : SearchQuery(org.graylog2.search.SearchQuery) ViewSummaryDTO(org.graylog.plugins.views.search.views.ViewSummaryDTO) BadRequestException(javax.ws.rs.BadRequestException) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)15 DateTime (org.joda.time.DateTime)15 Test (org.junit.Test)15 ElasticsearchBaseTest (org.graylog.testing.elasticsearch.ElasticsearchBaseTest)13 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)7 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 CountResult (org.graylog2.indexer.results.CountResult)4 SearchResult (org.graylog2.indexer.results.SearchResult)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Optional (java.util.Optional)3 Set (java.util.Set)3 FieldStatsResult (org.graylog2.indexer.results.FieldStatsResult)3 Maps (com.google.common.collect.Maps)2 Named (com.google.inject.name.Named)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2