public void ensureIndexTemplate(IndexSet indexSet) { final IndexSetConfig indexSetConfig = indexSet.getConfig(); final String templateName = indexSetConfig.indexTemplateName(); final IndexMapping indexMapping = indexMappingFactory.createIndexMapping(); final Map<String, Object> template = indexMapping.messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer(), -1); final PutTemplate request = new PutTemplate.Builder(templateName, template).build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Unable to create index template " + templateName); if (jestResult.isSucceeded()) { LOG.info("Successfully created index template {}", templateName); } }
private void createTemplates(Map<String, Map<String, Object>> templates) throws IOException { for (Map.Entry<String, Map<String, Object>> template : templates.entrySet()) { final String templateName = template.getKey(); final PutTemplate putTemplate = new PutTemplate.Builder(templateName, template.getValue()).build(); final JestResult result = client.execute(putTemplate); if (!result.isSucceeded()) { throw new IllegalStateException("Error while creating template \"" + templateName + "\": " + result.getErrorMessage()); } } }
String body= entry.getValue().toString(); PutTemplate putTemplate = new PutTemplate.Builder(templateName, body).build();
private void doInitialize() throws IOException { // Retrieve the server version final Version version = getServerVersion(); // Load the appropriate template final String template = templateLoader.load(version, templateLocation); // Post it to elastic final PutTemplate putTemplate = new PutTemplate.Builder(templateName, template).build(); final JestResult result = client.execute(putTemplate); if (!result.isSucceeded()) { // In case the template could not be created, we bail throw new IllegalStateException("Template '" + templateName + "' could not be persisted. Reason: " + result.getErrorMessage()); } }
public void ensureIndexTemplate(IndexSet indexSet) { final IndexSetConfig indexSetConfig = indexSet.getConfig(); final String templateName = indexSetConfig.indexTemplateName(); final IndexMapping indexMapping = indexMappingFactory.createIndexMapping(); final Map<String, Object> template = indexMapping.messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer(), -1); final PutTemplate request = new PutTemplate.Builder(templateName, template).build(); final JestResult jestResult = JestUtils.execute(jestClient, request, () -> "Unable to create index template " + templateName); if (jestResult.isSucceeded()) { LOG.info("Successfully created index template {}", templateName); } }
@Override public void execute(IndexTemplate indexTemplate) { TemplateAction templateAction = new PutTemplate.Builder(indexTemplate.getName(), indexTemplate.getSource()).build(); try { JestResult result = createClient().execute(templateAction); if (!result.isSucceeded()) { throw new ConfigurationException("IndexTemplate not added: " + result.getErrorMessage()); } } catch (IOException e) { throw new ConfigurationException("IndexTemplate not added: " + e.getMessage()); } }
private void doInitialize() throws IOException { // Retrieve the server version final Version version = getServerVersion(); // Load the appropriate template final String template = templateLoader.load(version, templateLocation); // Post it to elastic final PutTemplate putTemplate = new PutTemplate.Builder(templateName, template).build(); final JestResult result = client.execute(putTemplate); if (!result.isSucceeded()) { // In case the template could not be created, we bail throw new IllegalStateException("Template '" + templateName + "' could not be persisted. Reason: " + result.getErrorMessage()); } }