Search in sources :

Example 1 with Delete

use of io.searchbox.core.Delete in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method deleteIndexDocuments.

/**
 * The delete index documents function will delete a list of document in the index by a list of document ids.
 */
@Override
public final void deleteIndexDocuments(String indexName, String documentType, List<Integer> ids) {
    LOGGER.info("Deleting Elasticsearch documents from index, indexName={}, documentType={}, ids={}.", indexName, documentType, ids.stream().map(Object::toString).collect(Collectors.joining(",")));
    List<String> allIndices = getAliases(indexName);
    allIndices.forEach((index) -> {
        // Prepare a bulk request builder
        Bulk.Builder bulkBuilder = new Bulk.Builder();
        // For each document prepare a delete request and add it to the bulk request builder
        ids.forEach(id -> {
            BulkableAction action = new Delete.Builder(id.toString()).index(index).type(documentType).build();
            bulkBuilder.addAction(action);
        });
        JestResult jestResult = jestClientHelper.executeAction(bulkBuilder.build());
        // If there are failures log them
        if (!jestResult.isSucceeded()) {
            LOGGER.error("Bulk response error = {}", jestResult.getErrorMessage());
        }
    });
}
Also used : Delete(io.searchbox.core.Delete) BulkableAction(io.searchbox.action.BulkableAction) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) JsonObject(com.google.gson.JsonObject) Bulk(io.searchbox.core.Bulk) JestResult(io.searchbox.client.JestResult)

Example 2 with Delete

use of io.searchbox.core.Delete in project dq-easy-cloud by dq-open-cloud.

the class TransportClient method deleteDocument.

/**
 * 删除Document
 *
 * @throws Exception
 */
@Test
public void deleteDocument() throws Exception {
    Delete delete = new Delete.Builder("").index(indexName).type(typeName).build();
    JestResult result = jestClient.execute(delete);
    System.out.println(result.getJsonString());
}
Also used : Delete(io.searchbox.core.Delete) JestResult(io.searchbox.client.JestResult) Test(org.junit.Test)

Example 3 with Delete

use of io.searchbox.core.Delete in project herd by FINRAOS.

the class IndexFunctionsDaoImpl method deleteDocumentById.

/**
 * The delete document by id function will delete a document in the index by the document id.
 */
@Override
public final void deleteDocumentById(String indexName, String documentType, String id) {
    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={}.", indexName, documentType, id);
    Action action = new Delete.Builder(id).index(indexName).type(documentType).build();
    JestResult result = jestClientHelper.executeAction(action);
    LOGGER.info("Deleting Elasticsearch document from index, indexName={}, documentType={}, id={} is successfully {}. ", indexName, documentType, id, result.isSucceeded());
}
Also used : Delete(io.searchbox.core.Delete) SearchAction(org.elasticsearch.action.search.SearchAction) Action(io.searchbox.action.Action) BulkableAction(io.searchbox.action.BulkableAction) JestResult(io.searchbox.client.JestResult)

Aggregations

JestResult (io.searchbox.client.JestResult)3 Delete (io.searchbox.core.Delete)3 BulkableAction (io.searchbox.action.BulkableAction)2 JsonObject (com.google.gson.JsonObject)1 Action (io.searchbox.action.Action)1 Bulk (io.searchbox.core.Bulk)1 SearchAction (org.elasticsearch.action.search.SearchAction)1 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)1 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)1 Test (org.junit.Test)1