// nothing there, lets create it
if (isTemplateMissing) {
LOGGER.debug("No metrics template found in elasticsearch. Adding...");
HttpURLConnection putTemplateConnection = openConnection( "/_template/metrics_template", "PUT");
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());
}