code: private static void createMappingWithJson(RestHighLevelClient client, String index, String mapping, boolean merge)
              throws Exception {
          boolean mappingExist = isMappingExist(client, index);
          if (merge || !mappingExist) {
              if (mappingExist) {
                  logger.debug("Updating type for index [{}].", index);
              } else {
                  logger.debug("Mapping for [{}] index doesn't exist. Creating it.", index);
              }
              createTypeWithMappingInElasticsearch(client, index, mapping);
          } else {
              logger.debug("Mapping already exists in index [{}] and merge is not set.", index);
          }
  
          if (mappingExist) {
              logger.debug("Mapping definition for [{}] index succesfully merged.", index);
          } else {
              logger.debug("Mapping definition for [{}] index succesfully created.", index);
          }
      }
docs: Create a new type in Elasticsearch
  @param client Elasticsearch client
  @param index Index name
  @param mapping Mapping if any, null if no specific mapping
  @param merge Try to merge mapping if type already exists
  @throws Exception if the elasticsearch call is failing