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);
}
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);
}
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);
}
}
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();
}
}
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);
}
Aggregations