CountAction extends Action<CountRequest> { @Override public ActionResponse execute(CountRequest parameter) { SearchRequestBuilder query = getRequestBuilder(parameter); try { SearchResponse response = query.execute() .actionGet(getGetQueryTimeout()); return getResponse(response, parameter); } catch (ElasticsearchException e) { throw FoxtrotExceptions.createQueryExecutionException(parameter, e); } } CountAction(CountRequest parameter, AnalyticsLoader analyticsLoader); @Override void preprocess(); @Override String getMetricKey(); @Override String getRequestCacheKey(); @Override void validateImpl(CountRequest parameter); @Override ActionResponse execute(CountRequest parameter); @Override SearchRequestBuilder getRequestBuilder(CountRequest parameter); @Override ActionResponse getResponse(org.elasticsearch.action.ActionResponse response, CountRequest parameter);  }
@Test public void testCount() throws FoxtrotException { CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); countRequest.setDistinct(false); CountResponse countResponse = CountResponse.class.cast(getQueryExecutor().execute(countRequest)); assertNotNull(countResponse); assertEquals(11, countResponse.getCount()); }
@Test public void testCountWithFilter() throws FoxtrotException { CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); ArrayList<Filter> filters = new ArrayList<Filter>(); filters.add(new EqualsFilter("os", "android")); countRequest.setFilters(filters); countRequest.setDistinct(false); CountResponse countResponse = CountResponse.class.cast(getQueryExecutor().execute(countRequest)); assertNotNull(countResponse); assertEquals(7, countResponse.getCount()); }
@Test public void testCountDistinct() throws FoxtrotException { CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); countRequest.setDistinct(true); CountResponse countResponse = CountResponse.class.cast(getQueryExecutor().execute(countRequest)); assertNotNull(countResponse); assertEquals(2, countResponse.getCount()); }
@Test public void testCountDistinctWithFilter() throws FoxtrotException { CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); ArrayList<Filter> filters = new ArrayList<Filter>(); filters.add(new EqualsFilter("device", "nexus")); countRequest.setFilters(filters); countRequest.setDistinct(true); CountResponse countResponse = CountResponse.class.cast(getQueryExecutor().execute(countRequest)); assertNotNull(countResponse); assertEquals(2, countResponse.getCount()); }
@Test public void testCountDistinctWithFilterOnSameField() throws FoxtrotException { CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); ArrayList<Filter> filters = new ArrayList<Filter>(); filters.add(new EqualsFilter("os", "android")); countRequest.setFilters(filters); countRequest.setDistinct(true); CountResponse countResponse = CountResponse.class.cast(getQueryExecutor().execute(countRequest)); assertNotNull(countResponse); assertEquals(1, countResponse.getCount()); }