org.elasticsearch.action.support.master.AcknowledgedResponse Java Examples

The following examples show how to use org.elasticsearch.action.support.master.AcknowledgedResponse. 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 Project: crate   Author: crate   File: AlterTableOperation.java    License: Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Long> addColumnToTable(BoundAddColumn analysis, final FutureActionListener<AcknowledgedResponse, Long> result) {
    try {
        AlterTableRequest request = new AlterTableRequest(
            analysis.table().ident(),
            null,
            analysis.table().isPartitioned(),
            false,
            analysis.settings(),
            analysis.mapping()
        );
        transportAlterTableAction.execute(request, result);
        return result;
    } catch (IOException e) {
        return FutureActionListener.failedFuture(e);
    }
}
 
Example #2
Source Project: jetlinks-community   Author: jetlinks   File: AbstractElasticSearchIndexStrategy.java    License: Apache License 2.0 6 votes vote down vote up
protected Mono<Void> doPutIndex(ElasticSearchIndexMetadata metadata,
                                boolean justUpdateMapping) {
    String index = wrapIndex(metadata.getIndex());
    return this.indexExists(index)
        .flatMap(exists -> {
            if (exists) {
                return doLoadIndexMetadata(index)
                    .flatMap(oldMapping -> Mono.justOrEmpty(createPutMappingRequest(metadata, oldMapping)))
                    .flatMap(request -> ReactorActionListener.<AcknowledgedResponse>mono(
                        actionListener ->
                            client.getWriteClient()
                                .indices()
                                .putMappingAsync(request, RequestOptions.DEFAULT, actionListener)))
                    .then();
            }
            if (justUpdateMapping) {
                return Mono.empty();
            }
            return doCreateIndex(metadata);
        });
}
 
Example #3
Source Project: java-11-examples   Author: jveverka   File: DataServiceIndexTestsIT.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDataServiceIndexCreateDelete() throws IOException {
    try {
        dataService.deleteIndex(INDEX_NAME);
    } catch (Exception e) {
    }

    Optional<CreateIndexResponse> createIndexResponse = dataService.createIndex(INDEX_NAME, Utils.createMapping());
    Assert.assertTrue(createIndexResponse.isPresent());
    Assert.assertTrue(createIndexResponse.get().isAcknowledged());

    Optional<Boolean> isCreated = dataService.isIndexCreated(INDEX_NAME);
    Assert.assertNotNull(isCreated.isPresent());
    Assert.assertTrue(isCreated.get());

    Optional<AcknowledgedResponse> deleteIndexResponse = dataService.deleteIndex(INDEX_NAME);
    Assert.assertTrue(deleteIndexResponse.isPresent());
    Assert.assertTrue(deleteIndexResponse.get().isAcknowledged());

    isCreated = dataService.isIndexCreated(INDEX_NAME);
    Assert.assertNotNull(isCreated.isPresent());
    Assert.assertFalse(isCreated.get());
}
 
Example #4
Source Project: crate   Author: crate   File: TransportUpdateSettingsAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final UpdateSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    final Index[] concreteIndices = indexNameExpressionResolver.concreteIndices(state, request);
    UpdateSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpdateSettingsClusterStateUpdateRequest()
            .indices(concreteIndices)
            .settings(request.settings())
            .setPreserveExisting(request.isPreserveExisting())
            .ackTimeout(request.timeout())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.updateSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug(() -> new ParameterizedMessage("failed to update settings on indices [{}]", (Object) concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
 
Example #5
Source Project: ElasticUtils   Author: bytefish   File: ElasticSearchUtils.java    License: MIT License 6 votes vote down vote up
private static AcknowledgedResponse internalPutMapping(Client client, String indexName, IElasticSearchMapping mapping) throws IOException {

        String json = Strings.toString(mapping.getMapping());

        final PutMappingRequest putMappingRequest = new PutMappingRequest(indexName)
                .type(mapping.getIndexType())
                .source(json, XContentType.JSON);

        final AcknowledgedResponse putMappingResponse = client
                .admin()
                .indices()
                .putMapping(putMappingRequest)
                .actionGet();

        if(log.isDebugEnabled()) {
            log.debug("PutMappingResponse: isAcknowledged {}", putMappingResponse.isAcknowledged());
        }

        return putMappingResponse;
    }
 
Example #6
Source Project: crate   Author: crate   File: AlterTableOperation.java    License: Apache License 2.0 6 votes vote down vote up
public CompletableFuture<Long> executeAlterTableAddColumn(final BoundAddColumn analysis) {
    FutureActionListener<AcknowledgedResponse, Long> result = new FutureActionListener<>(r -> -1L);
    if (analysis.newPrimaryKeys() || analysis.hasNewGeneratedColumns()) {
        RelationName ident = analysis.table().ident();
        String stmt =
            String.format(Locale.ENGLISH, "SELECT COUNT(*) FROM \"%s\".\"%s\"", ident.schema(), ident.name());

        try {
            session().quickExec(stmt, new ResultSetReceiver(analysis, result), Row.EMPTY);
        } catch (Throwable t) {
            result.completeExceptionally(t);
        }
    } else {
        return addColumnToTable(analysis, result);
    }
    return result;
}
 
Example #7
Source Project: sfs   Author: pitchpoint-solutions   File: IndexUpdateMapping.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    PutMappingRequestBuilder request = elasticsearch.get().admin().indices()
            .preparePutMapping(index)
            .setSource(mapping)
            .setType(type);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(putMappingResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(putMappingResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #8
Source Project: sfs   Author: pitchpoint-solutions   File: IndexCreate.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    CreateIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareCreate(index);
    for (Map.Entry<String, String> entry : mappings.entrySet()) {
        String type = entry.getKey();
        String mapping = entry.getValue();
        request = request.addMapping(type, mapping);
    }
    if (settings != null) {
        request.setSettings(settings);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }

    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(createIndexResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(createIndexResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #9
Source Project: sfs   Author: pitchpoint-solutions   File: IndexDelete.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    DeleteIndexRequestBuilder request = elasticsearch.get().admin().indices().prepareDelete(index);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(response -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(response)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #10
Source Project: sfs   Author: pitchpoint-solutions   File: IndexUpdateSettings.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Observable<Boolean> call(String index) {
    Elasticsearch elasticsearch = vertxContext.verticle().elasticsearch();
    UpdateSettingsRequestBuilder request = elasticsearch.get().admin().indices().prepareUpdateSettings(index);
    request.setSettings(settings);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug(format("Request %s", Jsonify.toString(request)));
    }
    return elasticsearch.execute(vertxContext, request, elasticsearch.getDefaultAdminTimeout())
            .map(Optional::get)
            .doOnNext(updateSettingsResponse -> {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug(format("Response %s", Jsonify.toString(updateSettingsResponse)));
                }
            })
            .map(AcknowledgedResponse::isAcknowledged);
}
 
Example #11
Source Project: crate   Author: crate   File: AlterTableOperation.java    License: Apache License 2.0 6 votes vote down vote up
private CompletableFuture<Long> executeAlterTableSetOrReset(BoundAlterTable analysis) {
    try {
        AlterTableRequest request = new AlterTableRequest(
            analysis.table().ident(),
            analysis.partitionName().map(PartitionName::asIndexName).orElse(null),
            analysis.isPartitioned(),
            analysis.excludePartitions(),
            analysis.tableParameter().settings(),
            analysis.tableParameter().mappings()
        );
        FutureActionListener<AcknowledgedResponse, Long> listener = new FutureActionListener<>(r -> -1L);
        transportAlterTableAction.execute(request, listener);
        return listener;
    } catch (IOException e) {
        return FutureActionListener.failedFuture(e);
    }
}
 
Example #12
Source Project: crate   Author: crate   File: TransportSchemaUpdateAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(SchemaUpdateRequest request, ClusterState state, ActionListener<AcknowledgedResponse> listener) throws Exception {
    // ideally we'd handle the index mapping update together with the template update in a single clusterStateUpdateTask
    // but the index mapping-update logic is difficult to re-use
    if (IndexParts.isPartitioned(request.index().getName())) {
        updateTemplate(
            state.getMetaData().getTemplates(),
            request.index().getName(),
            request.mappingSource(),
            request.masterNodeTimeout()
        ).thenCompose(r -> updateMapping(request.index(), request.masterNodeTimeout(), request.mappingSource()))
            .thenApply(r -> new AcknowledgedResponse(r.isAcknowledged()))
            .whenComplete(ActionListener.toBiConsumer(listener));
    } else {
        updateMapping(request.index(), request.masterNodeTimeout(), request.mappingSource())
            .thenApply(r -> new AcknowledgedResponse(r.isAcknowledged()))
            .whenComplete(ActionListener.toBiConsumer(listener));
    }
}
 
Example #13
Source Project: crate   Author: crate   File: TransportOpenCloseTableOrPartitionAction.java    License: Apache License 2.0 6 votes vote down vote up
@Inject
public TransportOpenCloseTableOrPartitionAction(TransportService transportService,
                                                ClusterService clusterService,
                                                ThreadPool threadPool,
                                                IndexNameExpressionResolver indexNameExpressionResolver,
                                                AllocationService allocationService,
                                                DDLClusterStateService ddlClusterStateService,
                                                MetaDataIndexUpgradeService metaDataIndexUpgradeService,
                                                IndicesService indexServices) {
    super(ACTION_NAME,
        transportService,
        clusterService,
        threadPool,
        indexNameExpressionResolver,
        OpenCloseTableOrPartitionRequest::new,
        AcknowledgedResponse::new,
        AcknowledgedResponse::new,
        "open-table-or-partition");
    openExecutor = new OpenTableClusterStateTaskExecutor(indexNameExpressionResolver, allocationService,
        ddlClusterStateService, metaDataIndexUpgradeService, indexServices);
    closeExecutor = new CloseTableClusterStateTaskExecutor(indexNameExpressionResolver, allocationService,
        ddlClusterStateService);
}
 
Example #14
Source Project: crate   Author: crate   File: SwapTablePlan.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    boolean dropSource = Objects.requireNonNull(DataTypes.BOOLEAN.value(SymbolEvaluator.evaluate(
        plannerContext.transactionContext(),
        dependencies.functions(),
        swapTable.dropSource(),
        params,
        subQueryResults
    )), SwapTableAnalyzer.DROP_SOURCE + " option must be true or false, not null");

    RelationName source = swapTable.source().ident();
    SwapRelationsRequest request = new SwapRelationsRequest(
        Collections.singletonList(new RelationNameSwap(source, swapTable.target().ident())),
        dropSource ? Collections.singletonList(source) : emptyList()
    );
    OneRowActionListener<AcknowledgedResponse> listener = new OneRowActionListener<>(
        consumer,
        r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L)
    );
    dependencies.swapRelationsAction().execute(request, listener);
}
 
Example #15
Source Project: crate   Author: crate   File: InsertFromValues.java    License: Apache License 2.0 6 votes vote down vote up
private static CompletableFuture<AcknowledgedResponse> createIndices(TransportCreatePartitionsAction
                                                                         createPartitionsAction,
                                                                     Set<String> indices,
                                                                     ClusterService clusterService,
                                                                     UUID jobId) {
    MetaData metaData = clusterService.state().getMetaData();
    List<String> indicesToCreate = new ArrayList<>();
    for (var index : indices) {
        if (IndexParts.isPartitioned(index) && metaData.hasIndex(index) == false) {
            indicesToCreate.add(index);
        }
    }

    FutureActionListener<AcknowledgedResponse, AcknowledgedResponse> listener = new FutureActionListener<>(r -> r);
    createPartitionsAction.execute(new CreatePartitionsRequest(indicesToCreate, jobId), listener);
    return listener;
}
 
Example #16
Source Project: crate   Author: crate   File: TransportAnalyzeAction.java    License: Apache License 2.0 6 votes vote down vote up
private CompletableFuture<AcknowledgedResponse> publishTableStats(Map<RelationName, Stats> newTableStats) {
    List<DiscoveryNode> nodesOn41OrAfter = StreamSupport.stream(clusterService.state().nodes().spliterator(), false)
        .filter(x -> x.getVersion().onOrAfter(Version.V_4_1_0))
        .collect(Collectors.toList());
    var listener = new FutureActionListener<AcknowledgedResponse, AcknowledgedResponse>(x -> x);
    var multiListener = new MultiActionListener<>(
        nodesOn41OrAfter.size(),
        Collectors.reducing(
            new AcknowledgedResponse(true),
            (resp1, resp2) -> new AcknowledgedResponse(resp1.isAcknowledged() && resp2.isAcknowledged())
        ),
        listener
    );
    var responseHandler = new ActionListenerResponseHandler<>(
        multiListener,
        AcknowledgedResponse::new,
        ThreadPool.Names.SAME
    );
    PublishTableStatsRequest request = new PublishTableStatsRequest(newTableStats);
    for (DiscoveryNode node : nodesOn41OrAfter) {
        transportService.sendRequest(node, RECEIVE_TABLE_STATS, request, responseHandler);
    }
    return listener;
}
 
Example #17
Source Project: crate   Author: crate   File: TransportUpgradeSettingsAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final UpgradeSettingsRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    UpgradeSettingsClusterStateUpdateRequest clusterStateUpdateRequest = new UpgradeSettingsClusterStateUpdateRequest()
            .ackTimeout(request.timeout())
            .versions(request.versions())
            .masterNodeTimeout(request.masterNodeTimeout());

    updateSettingsService.upgradeIndexSettings(clusterStateUpdateRequest, new ActionListener<ClusterStateUpdateResponse>() {
        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug(() -> new ParameterizedMessage("failed to upgrade minimum compatibility version settings on indices [{}]", request.versions().keySet()), t);
            listener.onFailure(t);
        }
    });
}
 
Example #18
Source Project: crate   Author: crate   File: TransportDeleteIndexAction.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void masterOperation(final DeleteIndexRequest request, final ClusterState state, final ActionListener<AcknowledgedResponse> listener) {
    final Set<Index> concreteIndices = new HashSet<>(Arrays.asList(indexNameExpressionResolver.concreteIndices(state, request)));
    if (concreteIndices.isEmpty()) {
        listener.onResponse(new AcknowledgedResponse(true));
        return;
    }

    DeleteIndexClusterStateUpdateRequest deleteRequest = new DeleteIndexClusterStateUpdateRequest()
        .ackTimeout(request.timeout()).masterNodeTimeout(request.masterNodeTimeout())
        .indices(concreteIndices.toArray(new Index[concreteIndices.size()]));

    deleteIndexService.deleteIndices(deleteRequest, new ActionListener<ClusterStateUpdateResponse>() {

        @Override
        public void onResponse(ClusterStateUpdateResponse response) {
            listener.onResponse(new AcknowledgedResponse(response.isAcknowledged()));
        }

        @Override
        public void onFailure(Exception t) {
            logger.debug(() -> new ParameterizedMessage("failed to delete indices [{}]", concreteIndices), t);
            listener.onFailure(t);
        }
    });
}
 
Example #19
Source Project: crate   Author: crate   File: GCDangingArtifactsPlan.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row params,
                          SubQueryResults subQueryResults) {
    OneRowActionListener<AcknowledgedResponse> listener =
        new OneRowActionListener<>(consumer, r -> r.isAcknowledged() ? new Row1(1L) : new Row1(0L));

    dependencies.transportActionProvider().transportDeleteIndexAction().execute(
        new DeleteIndexRequest(IndexParts.DANGLING_INDICES_PREFIX_PATTERNS.toArray(new String[0])),
        listener
    );
}
 
Example #20
Source Project: anomaly-detection   Author: opendistro-for-elasticsearch   File: DeleteTests.java    License: Apache License 2.0 5 votes vote down vote up
public void testNewResponse() throws IOException {
    StreamInput input = mock(StreamInput.class);
    when(input.readByte()).thenReturn((byte) 0x01);
    AcknowledgedResponse response = new AcknowledgedResponse(input);

    assertTrue(response.isAcknowledged());
}
 
Example #21
Source Project: anomaly-detection   Author: opendistro-for-elasticsearch   File: IndexUtilsTests.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetIndexHealth_Alias() {
    String indexName = "test-2";
    String aliasName = "alias";
    createIndex(indexName);
    flush();
    AcknowledgedResponse response = client().admin().indices().prepareAliases().addAlias(indexName, aliasName).execute().actionGet();
    assertTrue(response.isAcknowledged());
    IndexUtils indexUtils = new IndexUtils(client(), clientUtil, clusterService());
    String status = indexUtils.getIndexHealthStatus(aliasName);
    assertTrue(status.equals("green") || status.equals("yellow"));
}
 
Example #22
Source Project: crate   Author: crate   File: SysSnapshotsTest.java    License: Apache License 2.0 5 votes vote down vote up
private void createRepository(String name) {
    AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(name)
        .setType("fs")
        .setSettings(Settings.builder()
            .put("location", new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath())
            .put("chunk_size", "5k")
            .put("compress", false)
        ).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
}
 
Example #23
Source Project: summerframework   Author: spring-avengers   File: ElasticsearchTemplate.java    License: Apache License 2.0 5 votes vote down vote up
public boolean createMapping(String index, String type, XContentBuilder mapping) throws IOException {
    log.info("mapping is:{}", mapping.toString());

    PutMappingRequest mappingRequest = Requests.putMappingRequest(index).source(mapping).type(type);
    AcknowledgedResponse putMappingResponse = esClient.admin().indices().putMapping(mappingRequest).actionGet();
    return putMappingResponse.isAcknowledged();
}
 
Example #24
Source Project: summerframework   Author: spring-avengers   File: ElasticsearchTemplate.java    License: Apache License 2.0 5 votes vote down vote up
public boolean deleteIndex(String index) {
    if (!isExistedIndex(index)) {
        return false;
    }
    AcknowledgedResponse deleteIndexResponse =
        esClient.admin().indices().prepareDelete(index).execute().actionGet();
    return deleteIndexResponse.isAcknowledged();
}
 
Example #25
Source Project: apm-agent-java   Author: elastic   File: AbstractEs6_4ClientInstrumentationTest.java    License: Apache License 2.0 5 votes vote down vote up
protected AcknowledgedResponse doDeleteIndex(DeleteIndexRequest deleteIndexRequest) throws IOException, ExecutionException, InterruptedException {
    if (async) {
        ClientMethod<DeleteIndexRequest, AcknowledgedResponse> method =
            (request, options, listener) -> client.indices().deleteAsync(request, options, listener);
        return invokeAsync(deleteIndexRequest, method);
    }
    return client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
}
 
Example #26
Source Project: java-11-examples   Author: jveverka   File: DataServiceImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Optional<AcknowledgedResponse> deleteIndex(String indexName) {
    try {
        DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);
        AcknowledgedResponse deleteResponse = client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);
        return Optional.of(deleteResponse);
    } catch (IOException e) {
        return Optional.empty();
    }
}
 
Example #27
Source Project: ElasticUtils   Author: bytefish   File: ElasticSearchUtils.java    License: MIT License 5 votes vote down vote up
public static AcknowledgedResponse updateMapping(RestHighLevelClient client, String indexName, IElasticSearchMapping mapping) {
    try {
        return internalUpdateMapping(client, indexName, mapping);
    } catch(Exception e) {
        if(log.isErrorEnabled()) {
            log.error("Error Updating Index", e);
        }
        throw new PutMappingFailedException(indexName, e);
    }
}
 
Example #28
Source Project: crate   Author: crate   File: SysRepositoriesServiceTest.java    License: Apache License 2.0 5 votes vote down vote up
private void createRepository(String name) {
    AcknowledgedResponse putRepositoryResponse = client().admin().cluster().preparePutRepository(name)
        .setType("fs")
        .setSettings(Settings.builder()
            .put("location", new File(TEMP_FOLDER.getRoot(), "backup").getAbsolutePath())
            .put("chunk_size", "5k")
            .put("compress", false)
        ).get();
    assertThat(putRepositoryResponse.isAcknowledged(), equalTo(true));
    repositories.add(name);
}
 
Example #29
Source Project: ElasticUtils   Author: bytefish   File: ElasticSearchUtils.java    License: MIT License 5 votes vote down vote up
public static AcknowledgedResponse putMapping(Client client, String indexName, IElasticSearchMapping mapping) {
    try {
        return internalPutMapping(client, indexName, mapping);
    } catch(Exception e) {
        if(log.isErrorEnabled()) {
            log.error("Error Creating Index", e);
        }
        throw new PutMappingFailedException(indexName, e);
    }
}
 
Example #30
Source Project: pybbs   Author: tomoya92   File: ElasticSearchService.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public boolean deleteIndex() {
    try {
        if (this.instance() == null) return false;
        DeleteIndexRequest request = new DeleteIndexRequest(name);
        request.indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);
        AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT);
        return response.isAcknowledged();
    } catch (IOException e) {
        log.error(e.getMessage());
        return false;
    }
}