code: private void addMappingToIndex(final String index, final String mappingType, final String mappingFilename) throws IOException {
  
          logger.info("Adding '{}' mapping to index '{}'...", mappingType, index);
  
          String resourcePath = "/" + index + "/_mapping/" + mappingType;
  
          if (doesResourceNotExist(resourcePath)) {
              HttpEntity entity = new NByteArrayEntity(loadTypeMappingSource(mappingFilename).getBytes(), ContentType.APPLICATION_JSON);
              elasticSearchAdminClient.performRequest(HttpMethod.PUT, resourcePath, Collections.emptyMap(), entity);
              logger.info("Added '{}' mapping", mappingType);
          } else {
              logger.info("Mapping '{}' already exists", mappingType);
          }
      }
docs: Adds a mapping type to an index if it does not exist.
  
  @param index           The name of the index.
  @param mappingType     The name of the mapping type.
  @param mappingFilename The name of the mapping file to use to add the mapping if it does not exist.
  @throws IOException If an error occurred during requests to ES.