org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RestHeadIndexTemplateAction.java    From Elasticsearch with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(request.param("name"));
    getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
    getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
    client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestResponseListener<GetIndexTemplatesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetIndexTemplatesResponse getIndexTemplatesResponse) {
            boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0;
            if (templateExists) {
                return new BytesRestResponse(OK);
            } else {
                return new BytesRestResponse(NOT_FOUND);
            }
        }
    });
}
 
Example #2
Source File: PartitionedTableIntegrationTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception {
    execute("create table t (id int primary key, date timestamp with time zone 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(DEFAULT_MAPPING_TYPE).toString();
    Map mapping = (Map) XContentFactory.xContent(mappingSource)
        .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource)
        .map()
        .get(DEFAULT_MAPPING_TYPE);
    assertNotNull(((Map) mapping.get("properties")).get("name"));
    assertNotNull(((Map) mapping.get("properties")).get("ft_name"));
}
 
Example #3
Source File: RestGetIndexTemplateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] names = Strings.splitStringByCommaToArray(request.param("name"));

    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;

    client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestBuilderListener<GetIndexTemplatesResponse>(channel) {
        @Override
        public RestResponse buildResponse(GetIndexTemplatesResponse getIndexTemplatesResponse, XContentBuilder builder) throws Exception {
            boolean templateExists = getIndexTemplatesResponse.getIndexTemplates().size() > 0;

            Map<String, String> paramsMap = Maps.newHashMap();
            paramsMap.put("reduce_mappings", "true");
            ToXContent.Params params = new ToXContent.DelegatingMapParams(paramsMap, request);

            builder.startObject();
            for (IndexTemplateMetaData indexTemplateMetaData : getIndexTemplatesResponse.getIndexTemplates()) {
                IndexTemplateMetaData.Builder.toXContent(indexTemplateMetaData, builder, params);
            }
            builder.endObject();

            RestStatus restStatus = (templateExists || implicitAll) ? OK : NOT_FOUND;

            return new BytesRestResponse(restStatus, builder);
        }
    });
}
 
Example #4
Source File: PartitionedTableIntegrationTest.java    From crate with Apache License 2.0 5 votes vote down vote up
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTable() throws Exception {
    execute("create table t (id int primary key, date timestamp with time zone 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(DEFAULT_MAPPING_TYPE).toString();
    Map mapping = (Map) XContentFactory.xContent(mappingSource)
        .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource)
        .map().get(DEFAULT_MAPPING_TYPE);
    assertNotNull(((Map) mapping.get("properties")).get("name"));
    // template order must not be touched
    assertThat(metaData.order(), is(100));
}
 
Example #5
Source File: AbstractESTest.java    From elasticsearch-migration with Apache License 2.0 4 votes vote down vote up
@SneakyThrows
protected boolean checkTemplateExists(String name) {
    final ActionFuture<GetIndexTemplatesResponse> response = client.admin().indices().getTemplates(new GetIndexTemplatesRequest(name));
    return !response.get().getIndexTemplates().isEmpty();
}
 
Example #6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetIndexTemplatesResponse> getTemplates(final GetIndexTemplatesRequest request) {
    return execute(GetIndexTemplatesAction.INSTANCE, request);
}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener<GetIndexTemplatesResponse> listener) {
    execute(GetIndexTemplatesAction.INSTANCE, request, listener);
}
 
Example #8
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetIndexTemplatesResponse> getTemplates(final GetIndexTemplatesRequest request) {
    return execute(GetIndexTemplatesAction.INSTANCE, request);
}
 
Example #9
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void getTemplates(final GetIndexTemplatesRequest request, final ActionListener<GetIndexTemplatesResponse> listener) {
    execute(GetIndexTemplatesAction.INSTANCE, request, listener);
}
 
Example #10
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Gets index template.
 */
ActionFuture<GetIndexTemplatesResponse> getTemplates(GetIndexTemplatesRequest request);
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an index template.
 */
void getTemplates(GetIndexTemplatesRequest request, ActionListener<GetIndexTemplatesResponse> listener);
 
Example #12
Source File: IndicesAdminClient.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Gets index template.
 */
ActionFuture<GetIndexTemplatesResponse> getTemplates(GetIndexTemplatesRequest request);
 
Example #13
Source File: IndicesAdminClient.java    From crate with Apache License 2.0 2 votes vote down vote up
/**
 * Gets an index template.
 */
void getTemplates(GetIndexTemplatesRequest request, ActionListener<GetIndexTemplatesResponse> listener);