public synchronized boolean insertDocuments(
      String indexName, Map<String, Map<String, Object>> documents)
      throws ElasticsearchResourceManagerException {
    LOG.info("Attempting to write {} documents to {}.", documents.size(), indexName);

    try {
      BulkRequest request = new BulkRequest();

      for (Map.Entry<String, Map<String, Object>> documentEntry : documents.entrySet()) {
        request.add(
            new IndexRequest(indexName)
                .id(documentEntry.getKey())
                .source(documentEntry.getValue()));
      }

      BulkResponse bulkResponse = elasticsearchClient.bulk(request, RequestOptions.DEFAULT);
      if (!bulkResponse.hasFailures()) {
        LOG.info("Successfully wrote {} documents to {}", documents.size(), indexName);
        return true;
      }

      return false;
    } catch (Exception e) {
      throw new ElasticsearchResourceManagerException("Error inserting documents.", e);
    }
  }
@Test
  public void testInsertDocumentsShouldInsert() throws IOException {
    assertThat(
            testManager.insertDocuments(
                INDEX_NAME, ImmutableMap.of("1", ImmutableMap.of("company", "Google LLC"))))
        .isEqualTo(true);

    verify(elasticsearchClient).bulk(any(BulkRequest.class), eq(RequestOptions.DEFAULT));
  }