EsClient { public long count(String name, String type) throws IOException { CloseableHttpClient client = HttpClients.createDefault(); HttpPost method = new HttpPost(String.format("http: try { EsRequest query = new EsRequest(); query.put("query", new MatchAllQuery().build()); StringEntity requestEntity = new StringEntity(query.toString(), ContentType.APPLICATION_JSON); method.setEntity(requestEntity); CloseableHttpResponse resp = client.execute(method); int status = resp.getStatusLine().getStatusCode(); if (status != HttpStatus.SC_OK) { throw new IOException(resp.getStatusLine().getReasonPhrase()); } return (Integer) EsResponse.read(resp.getEntity().getContent()).get("count"); } finally { method.releaseConnection(); } } EsClient(String host, int port); boolean indexExists(String name); boolean createIndex(String name, String type, EsRequest mappings); boolean deleteIndex(String name); boolean storeDocument(String name, String type, String id,
            EsRequest doc); EsRequest getDocument(String name, String type, String id); boolean deleteDocument(String name, String type, String id); void deleteAll(String name, String type); void flush(String name); void refresh(String name); EsResponse search(String name, String type, EsRequest query); long count(String name, String type);  }
@Test public void testCount() throws Exception { EsRequest doc = new EsRequest(); doc.put("field1", "value1"); assertTrue(client.storeDocument(INDEX_NAME, TYPE_NAME, "10", doc)); Thread.sleep(1500); long count = client.count(INDEX_NAME, TYPE_NAME); assertEquals(1, count); }