use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchServiceImplTest method searchShouldProperlySearchWithUserSettingsFacetFields.
@Test
public void searchShouldProperlySearchWithUserSettingsFacetFields() throws Exception {
AlertsUIUserSettings alertsUIUserSettings = new AlertsUIUserSettings();
alertsUIUserSettings.setFacetFields(Arrays.asList("source:type", "ip_dst_addr"));
when(alertsUIService.getAlertsUIUserSettings()).thenReturn(Optional.of(alertsUIUserSettings));
SearchRequest searchRequest = new SearchRequest();
searchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
searchRequest.setFacetFields(new ArrayList<>());
searchService.search(searchRequest);
SearchRequest expectedSearchRequest = new SearchRequest();
expectedSearchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
expectedSearchRequest.setFacetFields(Arrays.asList("source:type", "ip_dst_addr"));
verify(dao).search(eq(expectedSearchRequest));
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchServiceImplTest method searchShouldProperlySearch.
@Test
public void searchShouldProperlySearch() throws Exception {
SearchRequest searchRequest = new SearchRequest();
searchRequest.setIndices(Arrays.asList("bro"));
searchRequest.setFacetFields(Arrays.asList("ip_src_addr"));
searchService.search(searchRequest);
SearchRequest expectedSearchRequest = new SearchRequest();
expectedSearchRequest.setIndices(Arrays.asList("bro"));
expectedSearchRequest.setFacetFields(Arrays.asList("ip_src_addr"));
verify(dao).search(eq(expectedSearchRequest));
verifyNoMoreInteractions(dao);
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchServiceImplTest method searchShouldProperlySearchDefaultFacetFields.
@Test
public void searchShouldProperlySearchDefaultFacetFields() throws Exception {
when(environment.getProperty(SEARCH_FACET_FIELDS_SPRING_PROPERTY, String.class, "")).thenReturn("source:type,ip_src_addr");
when(alertsUIService.getAlertsUIUserSettings()).thenReturn(Optional.empty());
SearchRequest searchRequest = new SearchRequest();
searchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
searchRequest.setFacetFields(new ArrayList<>());
searchService.search(searchRequest);
SearchRequest expectedSearchRequest = new SearchRequest();
expectedSearchRequest.setIndices(Arrays.asList("bro", "snort", "metaalert"));
expectedSearchRequest.setFacetFields(Arrays.asList("source:type", "ip_src_addr"));
verify(dao).search(eq(expectedSearchRequest));
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class ElasticsearchDaoTest method searchShouldSortByGivenFields.
@Test
public void searchShouldSortByGivenFields() throws Exception {
// setup the column metadata
Map<String, FieldType> columnMetadata = new HashMap<>();
columnMetadata.put("sortByStringDesc", FieldType.TEXT);
columnMetadata.put("sortByIntAsc", FieldType.INTEGER);
// setup the dao
setup(RestStatus.OK, 25, columnMetadata);
// "sort by" fields for the search request
SortField[] expectedSortFields = { sortBy("sortByStringDesc", SortOrder.DESC), sortBy("sortByIntAsc", SortOrder.ASC), sortBy("sortByUndefinedDesc", SortOrder.DESC) };
// create a metron search request
final List<String> indices = Arrays.asList("bro", "snort");
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSize(2);
searchRequest.setIndices(indices);
searchRequest.setFrom(5);
searchRequest.setSort(Arrays.asList(expectedSortFields));
searchRequest.setQuery("some query");
// submit the metron search request
SearchResponse searchResponse = dao.search(searchRequest);
assertNotNull(searchResponse);
// capture the elasticsearch search request that was created
ArgumentCaptor<org.elasticsearch.action.search.SearchRequest> argument = ArgumentCaptor.forClass(org.elasticsearch.action.search.SearchRequest.class);
verify(requestSubmitter).submitSearch(argument.capture());
org.elasticsearch.action.search.SearchRequest request = argument.getValue();
// transform the request to JSON for validation
JSONParser parser = new JSONParser();
JSONObject json = (JSONObject) parser.parse(ElasticsearchUtils.toJSON(request).orElse("???"));
// validate the sort fields
JSONArray sortFields = (JSONArray) json.get("sort");
assertEquals(3, sortFields.size());
{
// sort by string descending
JSONObject aSortField = (JSONObject) sortFields.get(0);
JSONObject sortBy = (JSONObject) aSortField.get("sortByStringDesc");
assertEquals("desc", sortBy.get("order"));
assertEquals("_last", sortBy.get("missing"));
assertEquals("text", sortBy.get("unmapped_type"));
}
{
// sort by integer ascending
JSONObject aSortField = (JSONObject) sortFields.get(1);
JSONObject sortByIntAsc = (JSONObject) aSortField.get("sortByIntAsc");
assertEquals("asc", sortByIntAsc.get("order"));
assertEquals("_first", sortByIntAsc.get("missing"));
assertEquals("integer", sortByIntAsc.get("unmapped_type"));
}
{
// sort by unknown type
JSONObject aSortField = (JSONObject) sortFields.get(2);
JSONObject sortByUndefinedDesc = (JSONObject) aSortField.get("sortByUndefinedDesc");
assertEquals("desc", sortByUndefinedDesc.get("order"));
assertEquals("_last", sortByUndefinedDesc.get("missing"));
assertEquals("other", sortByUndefinedDesc.get("unmapped_type"));
}
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class ElasticsearchDaoTest method searchShouldThrowExceptionWhenMaxResultsAreExceeded.
@Test(expected = InvalidSearchException.class)
public void searchShouldThrowExceptionWhenMaxResultsAreExceeded() throws Exception {
int maxSearchResults = 20;
setup(RestStatus.OK, maxSearchResults);
SearchRequest searchRequest = new SearchRequest();
searchRequest.setSize(maxSearchResults + 1);
searchRequest.setQuery("");
dao.search(searchRequest);
// exception expected - size > max
}
Aggregations