use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest in project elasticsearch by elastic.
the class RestGetIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {
@Override
protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
return (templateExists || implicitAll) ? OK : NOT_FOUND;
}
});
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest in project graylog2-server by Graylog2.
the class IndicesTest method testCreateEnsuresIndexTemplateExists.
@Test
public void testCreateEnsuresIndexTemplateExists() throws Exception {
final String templateName = indexSetConfig.indexTemplateName();
final IndicesAdminClient client = this.client.admin().indices();
final GetIndexTemplatesRequest request = client.prepareGetTemplates(templateName).request();
final GetIndexTemplatesResponse responseBefore = client.getTemplates(request).actionGet();
assertThat(responseBefore.getIndexTemplates()).isEmpty();
indices.create("index_template_test", indexSet);
final GetIndexTemplatesResponse responseAfter = client.getTemplates(request).actionGet();
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 DeleteIndexTemplateRequest deleteRequest = client.prepareDeleteTemplate(templateName).request();
final DeleteIndexTemplateResponse deleteResponse = client.deleteTemplate(deleteRequest).actionGet();
assertThat(deleteResponse.isAcknowledged()).isTrue();
indices.delete("index_template_test");
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterTableAddColumnOnPartitionedTableWithoutPartitions.
@Test
public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception {
execute("create table t (id int primary key, date timestamp primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)");
ensureYellow();
execute("alter table t add column name string");
execute("alter table t add column ft_name string index using fulltext");
ensureYellow();
execute("select * from t");
assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "ft_name", "id", "name"));
GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0);
String mappingSource = metaData.mappings().get(Constants.DEFAULT_MAPPING_TYPE).toString();
Map mapping = (Map) XContentFactory.xContent(mappingSource).createParser(mappingSource).map().get(Constants.DEFAULT_MAPPING_TYPE);
assertNotNull(((Map) mapping.get("properties")).get("name"));
assertNotNull(((Map) mapping.get("properties")).get("ft_name"));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest in project crate by crate.
the class PartitionedTableIntegrationTest method testAlterTableAddColumnOnPartitionedTable.
@Test
public void testAlterTableAddColumnOnPartitionedTable() throws Exception {
execute("create table t (id int primary key, date timestamp primary key) " + "partitioned by (date) " + "clustered into 1 shards " + "with (number_of_replicas=0)");
execute("insert into t (id, date) values (1, '2014-01-01')");
execute("insert into t (id, date) values (10, '2015-01-01')");
ensureYellow();
refresh();
execute("alter table t add name string");
execute("select * from t");
assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "id", "name"));
GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0);
String mappingSource = metaData.mappings().get(Constants.DEFAULT_MAPPING_TYPE).toString();
Map mapping = (Map) XContentFactory.xContent(mappingSource).createParser(mappingSource).map().get(Constants.DEFAULT_MAPPING_TYPE);
assertNotNull(((Map) mapping.get("properties")).get("name"));
// template order must not be touched
assertThat(metaData.order(), is(100));
}
use of org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest 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();
}
Aggregations