Search in sources :

Example 1 with GetIndexTemplatesRequest

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;
        }
    });
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) GET(org.elasticsearch.rest.RestRequest.Method.GET) RestToXContentListener(org.elasticsearch.rest.action.RestToXContentListener) Set(java.util.Set) IOException(java.io.IOException) NOT_FOUND(org.elasticsearch.rest.RestStatus.NOT_FOUND) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) Settings(org.elasticsearch.common.settings.Settings) RestStatus(org.elasticsearch.rest.RestStatus) RestRequest(org.elasticsearch.rest.RestRequest) OK(org.elasticsearch.rest.RestStatus.OK) NodeClient(org.elasticsearch.client.node.NodeClient) HEAD(org.elasticsearch.rest.RestRequest.Method.HEAD) RestStatus(org.elasticsearch.rest.RestStatus) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)

Example 2 with GetIndexTemplatesRequest

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");
}
Also used : DeleteIndexTemplateResponse(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse) GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) IndicesAdminClient(org.elasticsearch.client.IndicesAdminClient) DeleteIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest) Test(org.junit.Test)

Example 3 with GetIndexTemplatesRequest

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"));
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) Test(org.junit.Test)

Example 4 with GetIndexTemplatesRequest

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));
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) IndexTemplateMetaData(org.elasticsearch.cluster.metadata.IndexTemplateMetaData) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) Test(org.junit.Test)

Example 5 with GetIndexTemplatesRequest

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();
}
Also used : GetIndexTemplatesResponse(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse) GetIndexTemplatesRequest(org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest) PutIndexTemplateRequest(org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest)

Aggregations

GetIndexTemplatesRequest (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest)5 GetIndexTemplatesResponse (org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse)5 IndexTemplateMetaData (org.elasticsearch.cluster.metadata.IndexTemplateMetaData)3 Test (org.junit.Test)3 IOException (java.io.IOException)1 Set (java.util.Set)1 DeleteIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest)1 DeleteIndexTemplateResponse (org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse)1 PutIndexTemplateRequest (org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest)1 IndicesAdminClient (org.elasticsearch.client.IndicesAdminClient)1 NodeClient (org.elasticsearch.client.node.NodeClient)1 Strings (org.elasticsearch.common.Strings)1 Settings (org.elasticsearch.common.settings.Settings)1 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)1 RestController (org.elasticsearch.rest.RestController)1 RestRequest (org.elasticsearch.rest.RestRequest)1 GET (org.elasticsearch.rest.RestRequest.Method.GET)1 HEAD (org.elasticsearch.rest.RestRequest.Method.HEAD)1 RestStatus (org.elasticsearch.rest.RestStatus)1 NOT_FOUND (org.elasticsearch.rest.RestStatus.NOT_FOUND)1