code: private void addIndex(final String index) throws IOException {
  
          logger.info("Adding index '{}'...", index);
  
          String resourcePath = "/" + index;
  
          if (doesResourceNotExist(resourcePath)) {
  
              try {
                  elasticSearchAdminClient.performRequest(HttpMethod.PUT, resourcePath);
  
                  logger.info("Added '{}' index", index);
              } catch (ResponseException e) {
  
                  boolean errorCreatingIndex = true;
  
                  Response errorResponse = e.getResponse();
                  if (errorResponse.getStatusLine().getStatusCode() == HttpStatus.SC_BAD_REQUEST) {
                      JsonNode root = objectMapper.readTree(EntityUtils.toString(errorResponse.getEntity()));
                      String errorCode = root.get("error").get("type").asText();
                      if ("index_already_exists_exception".equals(errorCode)) {
                          errorCreatingIndex = false;
                      }
                  }
  
                  if (errorCreatingIndex) {
                      throw e;
                  }
              }
          } else {
              logger.info("Index '{}' already exists", index);
          }
      }
docs: Adds an index to elasticsearch if it does not exist.
  
  @param index The name of the index to create.
  @throws IOException If an error occurred during requests to ES.