public long count(String indexName) throws ElasticsearchResourceManagerException {
    LOG.info("Fetching count from {}.", indexName);

    try {
      // Elasticsearch is near realtime, so refresh will guarantee reads are consistent
      elasticsearchClient.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);

      return elasticsearchClient
          .count(new CountRequest(indexName), RequestOptions.DEFAULT)
          .getCount();
    } catch (Exception e) {
      throw new ElasticsearchResourceManagerException(
          "Error fetching count from " + indexName + ".", e);
    }
  }
@Test
  public void testCountDocumentsShouldReturnInt() throws IOException {
    when(elasticsearchClient.count(any(CountRequest.class), eq(RequestOptions.DEFAULT)).getCount())
        .thenReturn(100L);

    assertThat(testManager.count(INDEX_NAME)).isEqualTo(100L);
  }