use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.
the class IndexTemplateBlocksIT method testIndexTemplatesWithBlocks.
public void testIndexTemplatesWithBlocks() throws IOException {
// creates a simple index template
client().admin().indices().preparePutTemplate("template_blocks").setPatterns(Collections.singletonList("te*")).setOrder(0).addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1").field("type", "text").field("store", true).endObject().startObject("field2").field("type", "keyword").field("store", true).endObject().endObject().endObject().endObject()).execute().actionGet();
try {
setClusterReadOnly(true);
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_blocks").execute().actionGet();
assertThat(response.getIndexTemplates(), hasSize(1));
assertBlocked(client().admin().indices().preparePutTemplate("template_blocks_2").setPatterns(Collections.singletonList("block*")).setOrder(0).addAlias(new Alias("alias_1")));
assertBlocked(client().admin().indices().prepareDeleteTemplate("template_blocks"));
} finally {
setClusterReadOnly(false);
}
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testBrokenMapping.
public void testBrokenMapping() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());
MapperParsingException e = expectThrows(MapperParsingException.class, () -> client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addMapping("type1", "{\"foo\": \"abcde\"}", XContentType.JSON).get());
assertThat(e.getMessage(), containsString("Failed to parse mapping "));
response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(0));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project elasticsearch by elastic.
the class SimpleIndexTemplateIT method testAliasInvalidFilterInvalidJson.
public void testAliasInvalidFilterInvalidJson() throws Exception {
//invalid json: put index template fails
PutIndexTemplateRequestBuilder putIndexTemplateRequestBuilder = client().admin().indices().preparePutTemplate("template_1").setPatterns(Collections.singletonList("te*")).addAlias(new Alias("invalid_alias").filter("abcde"));
IllegalArgumentException e = expectThrows(IllegalArgumentException.class, () -> putIndexTemplateRequestBuilder.get());
assertThat(e.getMessage(), equalTo("failed to parse filter for alias [invalid_alias]"));
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates("template_1").get();
assertThat(response.getIndexTemplates().size(), equalTo(0));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project zipkin by openzipkin.
the class NativeClient method ensureTemplate.
@Override
public void ensureTemplate(String name, String indexTemplate) {
GetIndexTemplatesResponse existingTemplates = client.admin().indices().getTemplates(new GetIndexTemplatesRequest(name)).actionGet();
if (!existingTemplates.getIndexTemplates().isEmpty()) {
return;
}
client.admin().indices().putTemplate(new PutIndexTemplateRequest(name).source(indexTemplate)).actionGet();
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse in project graylog2-server by Graylog2.
the class IndicesTest method testCreateOverwritesIndexTemplate.
@Test
public void testCreateOverwritesIndexTemplate() throws Exception {
final ObjectMapper mapper = new ObjectMapperProvider().get();
final String templateName = indexSetConfig.indexTemplateName();
final IndicesAdminClient client = this.client.admin().indices();
final ImmutableMap<String, Object> beforeMapping = ImmutableMap.of("_source", ImmutableMap.of("enabled", false), "properties", ImmutableMap.of("message", ImmutableMap.of("type", "string", "index", "not_analyzed")));
assertThat(client.preparePutTemplate(templateName).setTemplate(indexSet.getIndexWildcard()).addMapping(IndexMapping.TYPE_MESSAGE, beforeMapping).get().isAcknowledged()).isTrue();
final GetIndexTemplatesResponse responseBefore = client.prepareGetTemplates(templateName).get();
final List<IndexTemplateMetaData> beforeIndexTemplates = responseBefore.getIndexTemplates();
assertThat(beforeIndexTemplates).hasSize(1);
final ImmutableOpenMap<String, CompressedXContent> beforeMappings = beforeIndexTemplates.get(0).getMappings();
final Map<String, Object> actualMapping = mapper.readValue(beforeMappings.get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
assertThat(actualMapping.get(IndexMapping.TYPE_MESSAGE)).isEqualTo(beforeMapping);
indices.create("index_template_test", indexSet);
final GetIndexTemplatesResponse responseAfter = client.prepareGetTemplates(templateName).get();
assertThat(responseAfter.getIndexTemplates()).hasSize(1);
final IndexTemplateMetaData templateMetaData = responseAfter.getIndexTemplates().get(0);
assertThat(templateMetaData.getName()).isEqualTo(templateName);
assertThat(templateMetaData.getMappings().keysIt()).containsExactly(IndexMapping.TYPE_MESSAGE);
final Map<String, Object> mapping = mapper.readValue(templateMetaData.getMappings().get(IndexMapping.TYPE_MESSAGE).uncompressed(), new TypeReference<Map<String, Object>>() {
});
final Map<String, Object> expectedTemplate = new IndexMapping().messageTemplate(indexSet.getIndexWildcard(), indexSetConfig.indexAnalyzer());
assertThat(mapping).isEqualTo(expectedTemplate.get("mappings"));
final DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete("index_template_test");
}
Aggregations