org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse. 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: DefaultElasticSearchAdminService.java    From vertx-elasticsearch-service with Apache License 2.0 6 votes vote down vote up
@Override
public void putTemplate(String name, JsonObject source, TemplateOptions options, Handler<AsyncResult<Void>> resultHandler) {

    final PutIndexTemplateRequestBuilder builder = new PutIndexTemplateRequestBuilder(service.getClient(), PutIndexTemplateAction.INSTANCE, name)
            .setSource(source.encode().getBytes(Charsets.UTF_8), XContentType.JSON);

    builder.execute(new ActionListener<PutIndexTemplateResponse>() {
        @Override
        public void onResponse(PutIndexTemplateResponse putIndexTemplateResponse) {
            resultHandler.handle(Future.succeededFuture());
        }

        @Override
        public void onFailure(Exception e) {
            resultHandler.handle(Future.failedFuture(e));
        }
    });
}
 
Example #2
Source File: AlterTableOperation.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private ListenableFuture<Long> updateTemplate(Map<String, Object> newMappings,
                                              Settings newSettings,
                                              TableIdent tableIdent,
                                              AbstractDDLAnalyzedStatement statement) {
    String templateName = PartitionName.templateName(tableIdent.schema(), tableIdent.name());
    IndexTemplateMetaData indexTemplateMetaData =
            clusterService.state().metaData().templates().get(templateName);
    if (indexTemplateMetaData == null) {
        return Futures.immediateFailedFuture(new RuntimeException("Template for partitioned table is missing"));
    }

    // merge mappings
    Map<String, Object> mapping = mergeTemplateMapping(indexTemplateMetaData, newMappings);

    // merge settings
    Settings.Builder settingsBuilder = Settings.builder();
    settingsBuilder.put(indexTemplateMetaData.settings());
    settingsBuilder.put(newSettings);

    PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName)
            .create(false)
            .mapping(Constants.DEFAULT_MAPPING_TYPE, mapping)
            .order(indexTemplateMetaData.order())
            .settings(settingsBuilder.build())
            .template(indexTemplateMetaData.template());

    request.putHeader(LoginUserContext.USER_INFO_KEY, statement.getParameterContext().getLoginUserContext());
    for (ObjectObjectCursor<String, AliasMetaData> container : indexTemplateMetaData.aliases()) {
        Alias alias = new Alias(container.key);
        request.alias(alias);
    }

    SettableFuture<Long> result = SettableFuture.create();
    transportActionProvider.transportPutIndexTemplateAction().execute(request,
            new SettableFutureToNullActionListener<PutIndexTemplateResponse>(result));

    return result;
}
 
Example #3
Source File: ESCreateTemplateTask.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void onResponse(PutIndexTemplateResponse putIndexTemplateResponse) {
    if (putIndexTemplateResponse.isAcknowledged()) {
        future.set(TaskResult.ONE_ROW);
    } else {
        future.set(TaskResult.ZERO);
    }
}
 
Example #4
Source File: RestPutIndexTemplateAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
    putRequest.template(request.param("template", putRequest.template()));
    putRequest.order(request.paramAsInt("order", putRequest.order()));
    putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
    putRequest.create(request.paramAsBoolean("create", false));
    putRequest.cause(request.param("cause", ""));
    putRequest.source(request.content());
    client.admin().indices().putTemplate(putRequest, new AcknowledgedRestListener<PutIndexTemplateResponse>(channel));
}
 
Example #5
Source File: InitializerCommand.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Override
protected void run(Bootstrap<FoxtrotServerConfiguration> bootstrap, Namespace namespace, FoxtrotServerConfiguration configuration)
        throws Exception {
    ElasticsearchConfig esConfig = configuration.getElasticsearch();
    ElasticsearchConnection connection = new ElasticsearchConnection(esConfig);
    connection.start();

    ClusterHealthResponse clusterHealth = connection.getClient()
            .admin()
            .cluster()
            .health(new ClusterHealthRequest())
            .actionGet();
    int numDataNodes = clusterHealth.getNumberOfDataNodes();
    int numReplicas = (numDataNodes < 2) ? 0 : 1;

    logger.info("# data nodes: {}, Setting replica count to: {}", numDataNodes, numReplicas);

    createMetaIndex(connection, ElasticsearchConsolePersistence.INDEX, numReplicas);
    createMetaIndex(connection, ElasticsearchConsolePersistence.INDEX_V2, numReplicas);
    createMetaIndex(connection, TableMapStore.TABLE_META_INDEX, numReplicas);
    createMetaIndex(connection, ElasticsearchConsolePersistence.INDEX_HISTORY, numReplicas);
    createMetaIndex(connection, FqlStoreServiceImpl.FQL_STORE_INDEX, numReplicas);

    logger.info("Creating mapping");
    PutIndexTemplateRequest putIndexTemplateRequest = ElasticsearchUtils.getClusterTemplateMapping();
    PutIndexTemplateResponse response = connection.getClient()
            .admin()
            .indices()
            .putTemplate(putIndexTemplateRequest)
            .actionGet();
    logger.info("Created mapping: {}", response.isAcknowledged());

    logger.info("Creating hbase table");
    HBaseUtil.createTable(configuration.getHbase(), configuration.getHbase()
            .getTableName());
}
 
Example #6
Source File: PutIndexTemplateRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(PutIndexTemplateRequest request, PutIndexTemplateResponse response, XContentBuilder builder) throws IOException {
    builder.startObject()
            .field(Fields.OK, true)
            .field(Fields.ACKNOWLEDGED, response.isAcknowledged())
            .endObject();
    return builder;
}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<PutIndexTemplateResponse> putTemplate(final PutIndexTemplateRequest request) {
    return execute(PutIndexTemplateAction.INSTANCE, request);
}
 
Example #8
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void putTemplate(final PutIndexTemplateRequest request, final ActionListener<PutIndexTemplateResponse> listener) {
    execute(PutIndexTemplateAction.INSTANCE, request, listener);
}
 
Example #9
Source File: PutIndexTemplateRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<PutIndexTemplateResponse> doExecute(PutIndexTemplateRequest request) {
    return client.admin().indices().putTemplate(request);
}
 
Example #10
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Puts an index template.
 */
ActionFuture<PutIndexTemplateResponse> putTemplate(PutIndexTemplateRequest request);
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Puts an index template.
 */
void putTemplate(PutIndexTemplateRequest request, ActionListener<PutIndexTemplateResponse> listener);