Search in sources :

Example 16 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project nifi by apache.

the class TestDeleteElasticsearch5 method testDeleteServerFailure.

@Test
public void testDeleteServerFailure() throws IOException {
    restStatus = RestStatus.SERVICE_UNAVAILABLE;
    deleteResponse = new DeleteResponse(null, TYPE1, documentId, 1, true) {

        @Override
        public RestStatus status() {
            return restStatus;
        }
    };
    runner.enqueue(new byte[] {}, new HashMap<String, String>() {

        {
            put("documentId", documentId);
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_FAILURE, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(DeleteElasticsearch5.REL_FAILURE).get(0);
    assertNotNull(out);
    assertEquals(DeleteElasticsearch5.UNABLE_TO_DELETE_DOCUMENT_MESSAGE, out.getAttribute(DeleteElasticsearch5.ES_ERROR_MESSAGE));
    out.assertAttributeEquals(DeleteElasticsearch5.ES_REST_STATUS, restStatus.toString());
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) RestStatus(org.elasticsearch.rest.RestStatus) Test(org.junit.Test)

Example 17 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project nifi by apache.

the class TestDeleteElasticsearch5 method testDeleteNotFound.

@Test
public void testDeleteNotFound() throws IOException {
    restStatus = RestStatus.NOT_FOUND;
    deleteResponse = new DeleteResponse(null, TYPE1, documentId, 1, true) {

        @Override
        public RestStatus status() {
            return restStatus;
        }
    };
    runner.enqueue(new byte[] {}, new HashMap<String, String>() {

        {
            put("documentId", documentId);
        }
    });
    runner.run(1, true, true);
    runner.assertAllFlowFilesTransferred(DeleteElasticsearch5.REL_NOT_FOUND, 1);
    final MockFlowFile out = runner.getFlowFilesForRelationship(DeleteElasticsearch5.REL_NOT_FOUND).get(0);
    assertNotNull(out);
    assertEquals(DeleteElasticsearch5.UNABLE_TO_DELETE_DOCUMENT_MESSAGE, out.getAttribute(DeleteElasticsearch5.ES_ERROR_MESSAGE));
    out.assertAttributeEquals(DeleteElasticsearch5.ES_REST_STATUS, restStatus.toString());
    out.assertAttributeEquals(DeleteElasticsearch5.ES_FILENAME, documentId);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_INDEX, INDEX1);
    out.assertAttributeEquals(DeleteElasticsearch5.ES_TYPE, TYPE1);
}
Also used : MockFlowFile(org.apache.nifi.util.MockFlowFile) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) RestStatus(org.elasticsearch.rest.RestStatus) Test(org.junit.Test)

Example 18 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project fess by codelibs.

the class FessEsClient method delete.

public boolean delete(final String index, final String type, final String id, final long version) {
    try {
        final DeleteRequestBuilder builder = client.prepareDelete(index, type, id).setRefreshPolicy(RefreshPolicy.IMMEDIATE);
        if (version > 0) {
            builder.setVersion(version);
        }
        final DeleteResponse response = builder.execute().actionGet(ComponentUtil.getFessConfig().getIndexDeleteTimeout());
        return response.getResult() == Result.DELETED;
    } catch (final ElasticsearchException e) {
        throw new FessEsClientException("Failed to delete: " + index + "/" + type + "/" + id + "/" + version, e);
    }
}
Also used : DeleteRequestBuilder(org.elasticsearch.action.delete.DeleteRequestBuilder) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 19 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project wildfly-camel by wildfly-extras.

the class ElasticsearchIntegrationTest method testDeleteContent.

@Test
public void testDeleteContent() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {

        @Override
        public void configure() throws Exception {
            from("direct:index").to("elasticsearch://local?operation=INDEX&indexName=twitter&indexType=tweet");
            from("direct:get").to("elasticsearch://local?operation=GET_BY_ID&indexName=twitter&indexType=tweet");
            from("direct:delete").to("elasticsearch://local?operation=DELETE&indexName=twitter&indexType=tweet");
        }
    });
    camelctx.getComponent("elasticsearch", ElasticsearchComponent.class).setClient(client);
    camelctx.start();
    try {
        Map<String, String> indexedData = new HashMap<>();
        indexedData.put("content", "test");
        // Index some initial data
        ProducerTemplate template = camelctx.createProducerTemplate();
        template.sendBody("direct:index", indexedData);
        String indexId = template.requestBody("direct:index", indexedData, String.class);
        Assert.assertNotNull("Index id should not be null", indexId);
        // Retrieve indexed data
        GetResponse getResponse = template.requestBody("direct:get", indexId, GetResponse.class);
        Assert.assertNotNull("getResponse should not be null", getResponse);
        // Delete indexed data
        DeleteResponse deleteResponse = template.requestBody("direct:delete", indexId, DeleteResponse.class);
        Assert.assertNotNull("deleteResponse should not be null", deleteResponse);
        // Verify that the data has been deleted
        getResponse = template.requestBody("direct:get", indexId, GetResponse.class);
        Assert.assertNotNull("getResponse should not be null", getResponse);
        Assert.assertNull("getResponse source should be null", getResponse.getSource());
    } finally {
        camelctx.stop();
    }
}
Also used : DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CamelContext(org.apache.camel.CamelContext) ProducerTemplate(org.apache.camel.ProducerTemplate) DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) RouteBuilder(org.apache.camel.builder.RouteBuilder) HashMap(java.util.HashMap) ElasticsearchComponent(org.apache.camel.component.elasticsearch.ElasticsearchComponent) GetResponse(org.elasticsearch.action.get.GetResponse) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Example 20 with DeleteResponse

use of org.elasticsearch.action.delete.DeleteResponse in project syncope by apache.

the class ElasticsearchIndexManager method after.

@TransactionalEventListener
public void after(final AnyDeletedEvent event) {
    LOG.debug("About to delete index for {}[{}]", event.getAnyTypeKind(), event.getAnyKey());
    DeleteResponse response = client.prepareDelete(AuthContextUtils.getDomain().toLowerCase(), event.getAnyTypeKind().name(), event.getAnyKey()).get();
    LOG.debug("Index successfully deleted for {}[{}]: {}", event.getAnyTypeKind(), event.getAnyKey(), response);
}
Also used : DeleteResponse(org.elasticsearch.action.delete.DeleteResponse) TransactionalEventListener(org.springframework.transaction.event.TransactionalEventListener)

Aggregations

DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)42 Test (org.junit.Test)14 IndexResponse (org.elasticsearch.action.index.IndexResponse)13 GetResponse (org.elasticsearch.action.get.GetResponse)11 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)8 HashMap (java.util.HashMap)7 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)7 MultiGetResponse (org.elasticsearch.action.get.MultiGetResponse)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 MockFlowFile (org.apache.nifi.util.MockFlowFile)5 ElasticsearchException (org.elasticsearch.ElasticsearchException)5 IndexRequest (org.elasticsearch.action.index.IndexRequest)5 IOException (java.io.IOException)4 ExecutionException (java.util.concurrent.ExecutionException)3 ElasticsearchTimeoutException (org.elasticsearch.ElasticsearchTimeoutException)3 UpdateResponse (org.elasticsearch.action.update.UpdateResponse)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 CamelContext (org.apache.camel.CamelContext)2 ProducerTemplate (org.apache.camel.ProducerTemplate)2