Search in sources :

Example 6 with SearchRequest

use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.

the class SearchIntegrationTest method sort_descending_with_missing_fields.

@Test
public void sort_descending_with_missing_fields() throws Exception {
    SearchRequest request = JSONUtils.INSTANCE.load(sortDescendingWithMissingFields, SearchRequest.class);
    SearchResponse response = dao.search(request);
    Assert.assertEquals(10, response.getTotal());
    List<SearchResult> results = response.getResults();
    Assert.assertEquals(10, results.size());
    // validate sorted order - there are only 2 with a 'threat:triage:score'
    Assert.assertEquals("20", results.get(0).getSource().get("threat:triage:score"));
    Assert.assertEquals("10", results.get(1).getSource().get("threat:triage:score"));
    // the remaining are missing the 'threat:triage:score' and should be sorted last
    for (int i = 2; i < 10; i++) {
        Assert.assertFalse(results.get(i).getSource().containsKey("threat:triage:score"));
    }
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) SearchResult(org.apache.metron.indexing.dao.search.SearchResult) SearchResponse(org.apache.metron.indexing.dao.search.SearchResponse) Test(org.junit.Test)

Example 7 with SearchRequest

use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.

the class SearchIntegrationTest method exceeding_max_resulsts_throws_exception.

@Test
public void exceeding_max_resulsts_throws_exception() throws Exception {
    thrown.expect(InvalidSearchException.class);
    thrown.expectMessage("Search result size must be less than 100");
    SearchRequest request = JSONUtils.INSTANCE.load(exceededMaxResultsQuery, SearchRequest.class);
    dao.search(request);
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) Test(org.junit.Test)

Example 8 with SearchRequest

use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.

the class SearchIntegrationTest method bad_facet_query_throws_exception.

@Test
public void bad_facet_query_throws_exception() throws Exception {
    thrown.expect(InvalidSearchException.class);
    thrown.expectMessage("Failed to execute search");
    SearchRequest request = JSONUtils.INSTANCE.load(badFacetQuery, SearchRequest.class);
    dao.search(request);
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) Test(org.junit.Test)

Example 9 with SearchRequest

use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.

the class SearchIntegrationTest method no_results_returned_when_query_does_not_match.

@Test
public void no_results_returned_when_query_does_not_match() throws Exception {
    SearchRequest request = JSONUtils.INSTANCE.load(noResultsFieldsQuery, SearchRequest.class);
    SearchResponse response = dao.search(request);
    Assert.assertEquals(0, response.getTotal());
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) SearchResponse(org.apache.metron.indexing.dao.search.SearchResponse) Test(org.junit.Test)

Example 10 with SearchRequest

use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.

the class SearchServiceImplTest method searchShouldProperlySearchWithEmptyDefaultFacetFields.

@Test
public void searchShouldProperlySearchWithEmptyDefaultFacetFields() throws Exception {
    when(environment.getProperty(SEARCH_FACET_FIELDS_SPRING_PROPERTY, String.class, "")).thenReturn("");
    SearchRequest searchRequest = new SearchRequest();
    searchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
    searchService.search(searchRequest);
    SearchRequest expectedSearchRequest = new SearchRequest();
    expectedSearchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
    verify(dao).search(eq(expectedSearchRequest));
}
Also used : SearchRequest(org.apache.metron.indexing.dao.search.SearchRequest) Test(org.junit.Test)

Aggregations

SearchRequest (org.apache.metron.indexing.dao.search.SearchRequest)29 Test (org.junit.Test)26 SearchResponse (org.apache.metron.indexing.dao.search.SearchResponse)17 SearchResult (org.apache.metron.indexing.dao.search.SearchResult)10 SortField (org.apache.metron.indexing.dao.search.SortField)5 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 FieldType (org.apache.metron.indexing.dao.search.FieldType)3 GetRequest (org.apache.metron.indexing.dao.search.GetRequest)3 InvalidSearchException (org.apache.metron.indexing.dao.search.InvalidSearchException)3 JSONObject (org.json.simple.JSONObject)3 IOException (java.io.IOException)2 JSONArray (org.json.simple.JSONArray)2 JSONParser (org.json.simple.parser.JSONParser)2 List (java.util.List)1 Optional (java.util.Optional)1 ElasticsearchDao (org.apache.metron.elasticsearch.dao.ElasticsearchDao)1 AccessConfig (org.apache.metron.indexing.dao.AccessConfig)1 IndexDao (org.apache.metron.indexing.dao.IndexDao)1