RestElasticClient implements ElasticClient { @Override public ElasticResponse search(String searchIndices, String type, ElasticRequest request) throws IOException { final StringBuilder pathBuilder = new StringBuilder("/" + searchIndices); if (getVersion() < 7) { pathBuilder.append("/" + type); } pathBuilder.append("/_search"); final Map<String,Object> requestBody = new HashMap<>(); if (request.getSize() != null) { requestBody.put("size", request.getSize()); } if (request.getFrom() != null) { requestBody.put("from", request.getFrom()); } if (request.getScroll() != null) { pathBuilder.append("?scroll=").append(request.getScroll()).append("s"); } final List<String> sourceIncludes = request.getSourceIncludes(); if (sourceIncludes.size() == 1) { requestBody.put("_source", sourceIncludes.get(0)); } else if (!sourceIncludes.isEmpty()) { requestBody.put("_source", sourceIncludes); } if (!request.getFields().isEmpty()) { final String key = getVersion() >= 5 ? "stored_fields" : "fields"; requestBody.put(key, request.getFields()); } if (!request.getSorts().isEmpty()) { requestBody.put("sort", request.getSorts()); } if (request.getQuery() != null) { requestBody.put("query", request.getQuery()); } if (request.getAggregations() != null) { requestBody.put("aggregations", request.getAggregations()); } return parseResponse(performRequest("POST", pathBuilder.toString(), requestBody)); } RestElasticClient(RestClient client);  RestElasticClient(RestClient client, RestClient proxyClient, boolean enableRunAs); @Override double getVersion(); @Override List<String> getTypes(String indexName); @Override Map<String, Object> getMapping(String indexName, String type); @Override ElasticResponse search(String searchIndices, String type, ElasticRequest request); @Override ElasticResponse scroll(String scrollId, Integer scrollTime); @Override void clearScroll(Set<String> scrollIds); @Override void close(); @SuppressWarnings("unchecked") static void removeMapping(String parent, String key, Map<String,Object> data, String currentParent);  }
@Test(expected=IllegalStateException.class) public void testMissingAuth() throws IOException { when(mockStx.getAuthentication()).thenReturn(null); proxyClient.search("status_s", "active", new ElasticRequest()); }
@Test(expected=IllegalStateException.class) public void testUnauthenticated() throws IOException { when(mockAuth.isAuthenticated()).thenReturn(false); proxyClient.search("status_s", "active", new ElasticRequest()); }