use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchIntegrationTest method returns_results_only_for_specified_indices.
@Test
public void returns_results_only_for_specified_indices() throws Exception {
SearchRequest request = JSONUtils.INSTANCE.load(indexQuery, SearchRequest.class);
SearchResponse response = dao.search(request);
Assert.assertEquals(5, response.getTotal());
List<SearchResult> results = response.getResults();
for (int i = 5, j = 0; i > 0; i--, j++) {
Assert.assertEquals("bro", results.get(j).getSource().get("source:type"));
Assert.assertEquals(i, results.get(j).getSource().get("timestamp"));
}
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchIntegrationTest method sort_by_guid.
@Test
public void sort_by_guid() throws Exception {
SearchRequest request = JSONUtils.INSTANCE.load(sortByGuidQuery, SearchRequest.class);
SearchResponse response = dao.search(request);
Assert.assertEquals(5, response.getTotal());
List<SearchResult> results = response.getResults();
for (int i = 0; i < 5; ++i) {
Map<String, Object> source = results.get(i).getSource();
Assert.assertEquals(1, source.size());
Assert.assertEquals(source.get("guid"), "bro_" + (i + 1));
}
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchIntegrationTest method queries_fields.
@Test
public void queries_fields() throws Exception {
SearchRequest request = JSONUtils.INSTANCE.load(fieldsQuery, SearchRequest.class);
SearchResponse response = dao.search(request);
Assert.assertEquals(10, response.getTotal());
List<SearchResult> results = response.getResults();
for (int i = 0; i < 5; ++i) {
Map<String, Object> source = results.get(i).getSource();
Assert.assertEquals(1, source.size());
Assert.assertNotNull(source.get("ip_src_addr"));
}
for (int i = 5; i < 10; ++i) {
Map<String, Object> source = results.get(i).getSource();
Assert.assertEquals(1, source.size());
Assert.assertNotNull(source.get("ip_src_addr"));
}
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchIntegrationTest method facet_query_yields_field_types.
@Test
public void facet_query_yields_field_types() throws Exception {
SearchRequest request = JSONUtils.INSTANCE.load(facetQuery, SearchRequest.class);
SearchResponse response = dao.search(request);
Assert.assertEquals(10, response.getTotal());
Map<String, Map<String, Long>> facetCounts = response.getFacetCounts();
Assert.assertEquals(8, facetCounts.size());
Map<String, Long> sourceTypeCounts = facetCounts.get("source:type");
Assert.assertEquals(2, sourceTypeCounts.size());
Assert.assertEquals(new Long(5), sourceTypeCounts.get("bro"));
Assert.assertEquals(new Long(5), sourceTypeCounts.get("snort"));
Map<String, Long> ipSrcAddrCounts = facetCounts.get("ip_src_addr");
Assert.assertEquals(8, ipSrcAddrCounts.size());
Assert.assertEquals(new Long(3), ipSrcAddrCounts.get("192.168.1.1"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.2"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.3"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.4"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.5"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.6"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.7"));
Assert.assertEquals(new Long(1), ipSrcAddrCounts.get("192.168.1.8"));
Map<String, Long> ipSrcPortCounts = facetCounts.get("ip_src_port");
Assert.assertEquals(10, ipSrcPortCounts.size());
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8001"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8002"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8003"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8004"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8005"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8006"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8007"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8008"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8009"));
Assert.assertEquals(new Long(1), ipSrcPortCounts.get("8010"));
Map<String, Long> longFieldCounts = facetCounts.get("long_field");
Assert.assertEquals(2, longFieldCounts.size());
Assert.assertEquals(new Long(8), longFieldCounts.get("10000"));
Assert.assertEquals(new Long(2), longFieldCounts.get("20000"));
Map<String, Long> timestampCounts = facetCounts.get("timestamp");
Assert.assertEquals(10, timestampCounts.size());
Assert.assertEquals(new Long(1), timestampCounts.get("1"));
Assert.assertEquals(new Long(1), timestampCounts.get("2"));
Assert.assertEquals(new Long(1), timestampCounts.get("3"));
Assert.assertEquals(new Long(1), timestampCounts.get("4"));
Assert.assertEquals(new Long(1), timestampCounts.get("5"));
Assert.assertEquals(new Long(1), timestampCounts.get("6"));
Assert.assertEquals(new Long(1), timestampCounts.get("7"));
Assert.assertEquals(new Long(1), timestampCounts.get("8"));
Assert.assertEquals(new Long(1), timestampCounts.get("9"));
Assert.assertEquals(new Long(1), timestampCounts.get("10"));
Map<String, Long> latitudeCounts = facetCounts.get("latitude");
Assert.assertEquals(2, latitudeCounts.size());
List<String> latitudeKeys = new ArrayList<>(latitudeCounts.keySet());
Collections.sort(latitudeKeys);
Assert.assertEquals(48.0001, Double.parseDouble(latitudeKeys.get(0)), 0.00001);
Assert.assertEquals(48.5839, Double.parseDouble(latitudeKeys.get(1)), 0.00001);
Assert.assertEquals(new Long(2), latitudeCounts.get(latitudeKeys.get(0)));
Assert.assertEquals(new Long(8), latitudeCounts.get(latitudeKeys.get(1)));
Map<String, Long> scoreFieldCounts = facetCounts.get("score");
Assert.assertEquals(4, scoreFieldCounts.size());
List<String> scoreFieldKeys = new ArrayList<>(scoreFieldCounts.keySet());
Collections.sort(scoreFieldKeys);
Assert.assertEquals(10.0, Double.parseDouble(scoreFieldKeys.get(0)), 0.00001);
Assert.assertEquals(20.0, Double.parseDouble(scoreFieldKeys.get(1)), 0.00001);
Assert.assertEquals(50.0, Double.parseDouble(scoreFieldKeys.get(2)), 0.00001);
Assert.assertEquals(98.0, Double.parseDouble(scoreFieldKeys.get(3)), 0.00001);
Assert.assertEquals(new Long(4), scoreFieldCounts.get(scoreFieldKeys.get(0)));
Assert.assertEquals(new Long(2), scoreFieldCounts.get(scoreFieldKeys.get(1)));
Assert.assertEquals(new Long(3), scoreFieldCounts.get(scoreFieldKeys.get(2)));
Assert.assertEquals(new Long(1), scoreFieldCounts.get(scoreFieldKeys.get(3)));
Map<String, Long> isAlertCounts = facetCounts.get("is_alert");
Assert.assertEquals(2, isAlertCounts.size());
Assert.assertEquals(new Long(6), isAlertCounts.get("true"));
Assert.assertEquals(new Long(4), isAlertCounts.get("false"));
}
use of org.apache.metron.indexing.dao.search.SearchRequest in project metron by apache.
the class SearchIntegrationTest method disabled_facet_query_returns_null_count.
@Test
public void disabled_facet_query_returns_null_count() throws Exception {
SearchRequest request = JSONUtils.INSTANCE.load(disabledFacetQuery, SearchRequest.class);
SearchResponse response = dao.search(request);
Assert.assertNull(response.getFacetCounts());
}
Aggregations