docs: private void checkForIndexTemplate() {
          try {
              HttpURLConnection connection = openConnection( "/_template/metrics_template", "HEAD");
              if (connection == null) {
                  LOGGER.error("Could not connect to any configured elasticsearch instances: {}", Arrays.asList(hosts));
                  return;
              }
              connection.disconnect();
  
              boolean isTemplateMissing = connection.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND;
  
              // nothing there, lets create it
              if (isTemplateMissing) {
                  LOGGER.debug("No metrics template found in elasticsearch. Adding...");
                  HttpURLConnection putTemplateConnection = openConnection( "/_template/metrics_template", "PUT");
                  if(putTemplateConnection == null) {
                      LOGGER.error("Error adding metrics template to elasticsearch");
                      return;
                  }
  
                  JsonGenerator json = new JsonFactory().createGenerator(putTemplateConnection.getOutputStream());
                  json.writeStartObject();
                  json.writeStringField("template", index + "*");
                  json.writeObjectFieldStart("mappings");
  
                  json.writeObjectFieldStart("_default_");
                  json.writeObjectFieldStart("_all");
                  json.writeBooleanField("enabled", false);
                  json.writeEndObject();
                  json.writeObjectFieldStart("properties");
                  json.writeObjectFieldStart("name");
                  json.writeObjectField("type", "string");
                  json.writeObjectField("index", "not_analyzed");
                  json.writeEndObject();
                  json.writeEndObject();
                  json.writeEndObject();
  
                  json.writeEndObject();
                  json.writeEndObject();
                  json.flush();
  
                  putTemplateConnection.disconnect();
                  if (putTemplateConnection.getResponseCode() != 200) {
                      LOGGER.error("Error adding metrics template to elasticsearch: {}/{}" + putTemplateConnection.getResponseCode(), putTemplateConnection.getResponseMessage());
                  }
              }
              checkedForIndexTemplate = true;
          } catch (IOException e) {
              LOGGER.error("Error when checking/adding metrics template to elasticsearch", e);
          }
      }