MultiQueryAction extends Action<MultiQueryRequest> { @Override public ActionResponse execute(MultiQueryRequest parameter) { MultiSearchRequestBuilder multiSearchRequestBuilder = getRequestBuilder(parameter); try { LOGGER.info("Search: {}", multiSearchRequestBuilder); MultiSearchResponse multiSearchResponse = multiSearchRequestBuilder.execute() .actionGet(); return getResponse(multiSearchResponse, parameter); } catch (ElasticsearchException e) { throw FoxtrotExceptions.createQueryExecutionException(parameter, e); } } MultiQueryAction(MultiQueryRequest parameter, AnalyticsLoader analyticsLoader); @Override void preprocess(); @Override String getMetricKey(); @Override String getRequestCacheKey(); @Override void validateImpl(MultiQueryRequest parameter); @Override ActionResponse execute(MultiQueryRequest parameter); @Override MultiSearchRequestBuilder getRequestBuilder(MultiQueryRequest parameter); @Override ActionResponse getResponse(org.elasticsearch.action.ActionResponse multiSearchResponse, MultiQueryRequest parameter);  }
@Test public void testMultiQuery() throws FoxtrotException, JsonProcessingException { HashMap<String, ActionRequest> requests = Maps.newHashMap(); Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.asc); resultSort.setField("_timestamp"); query.setSort(resultSort); requests.put("1", query); CountRequest countRequest = new CountRequest(); countRequest.setTable(TestUtils.TEST_TABLE_NAME); countRequest.setField("os"); countRequest.setDistinct(false); requests.put("2", countRequest); MultiQueryRequest multiQueryRequest = new MultiQueryRequest(requests); ActionResponse actionResponse = getQueryExecutor().execute(multiQueryRequest); MultiQueryResponse multiQueryResponse = null; if(actionResponse instanceof MultiQueryResponse) { multiQueryResponse = (MultiQueryResponse)actionResponse; } assertNotNull(multiQueryResponse); QueryResponse queryResponse = (QueryResponse)multiQueryResponse.getResponses() .get("1"); CountResponse countResponse = (CountResponse)multiQueryResponse.getResponses() .get("2"); assertEquals(9, countResponse.getCount()); }
@Test public void testQueryNoFilterAscending() throws FoxtrotException, JsonProcessingException { HashMap<String, ActionRequest> requests = Maps.newHashMap(); Query query = new Query(); query.setTable(TestUtils.TEST_TABLE_NAME); ResultSort resultSort = new ResultSort(); resultSort.setOrder(ResultSort.Order.asc); resultSort.setField("_timestamp"); query.setSort(resultSort); requests.put("1", query); requests.put("2", query); MultiQueryRequest multiQueryRequest = new MultiQueryRequest(requests); List<Document> documents = new ArrayList<>(); documents.add( TestUtils.getDocument("W", 1397658117001L, new Object[]{"os", "android", "device", "nexus", "battery", 99}, getMapper())); documents.add( TestUtils.getDocument("X", 1397658117002L, new Object[]{"os", "android", "device", "nexus", "battery", 74}, getMapper())); documents.add( TestUtils.getDocument("Y", 1397658117003L, new Object[]{"os", "android", "device", "nexus", "battery", 48}, getMapper())); documents.add( TestUtils.getDocument("Z", 1397658117004L, new Object[]{"os", "android", "device", "nexus", "battery", 24}, getMapper())); documents.add( TestUtils.getDocument("A", 1397658118000L, new Object[]{"os", "android", "version", 1, "device", "nexus"}, getMapper())); documents.add( TestUtils.getDocument("B", 1397658118001L, new Object[]{"os", "android", "version", 1, "device", "galaxy"}, getMapper())); documents.add( TestUtils.getDocument("C", 1397658118002L, new Object[]{"os", "android", "version", 2, "device", "nexus"}, getMapper())); documents.add(TestUtils.getDocument("D", 1397658118003L, new Object[]{"os", "ios", "version", 1, "device", "iphone"}, getMapper())); documents.add(TestUtils.getDocument("E", 1397658118004L, new Object[]{"os", "ios", "version", 2, "device", "ipad"}, getMapper())); MultiQueryResponse multiQueryResponse = MultiQueryResponse.class.cast(getQueryExecutor().execute(multiQueryRequest)); for(Map.Entry<String, ActionResponse> response : multiQueryResponse.getResponses() .entrySet()) { compare(documents, ((QueryResponse)response.getValue()).getDocuments()); } }