use of org.elasticsearch.action.delete.DeleteResponse in project molgenis by molgenis.
the class ClientFacade method deleteById.
public void deleteById(Index index, Document document) {
if (LOG.isTraceEnabled()) {
LOG.trace("Deleting doc with id '{}' in index '{}' ...", document.getId(), index.getName());
}
String indexName = index.getName();
String documentId = document.getId();
DeleteRequestBuilder deleteRequest = client.prepareDelete().setIndex(indexName).setType(indexName).setId(documentId);
DeleteResponse deleteResponse;
try {
deleteResponse = deleteRequest.get();
} catch (ResourceNotFoundException e) {
LOG.error("", e);
throw new UnknownIndexException(index.getName());
} catch (ElasticsearchException e) {
LOG.debug("", e);
throw new IndexException(format("Error deleting doc with id '%s' in index '%s'.", documentId, indexName));
}
if (LOG.isDebugEnabled()) {
LOG.debug("Deleted doc with id '{}' in index '{}' and status '{}'", documentId, indexName, deleteResponse.getResult());
}
}
use of org.elasticsearch.action.delete.DeleteResponse in project opencast by opencast.
the class AbstractSearchIndex method delete.
@Override
public boolean delete(String documentType, String uid) throws SearchIndexException {
logger.debug("Removing element with id '{}' from searching index '{}'", uid, getIndexName());
DeleteRequestBuilder deleteRequest = getSearchClient().prepareDelete(getIndexName(), documentType, uid);
deleteRequest.setRefresh(true);
DeleteResponse delete = deleteRequest.execute().actionGet();
if (!delete.isFound()) {
logger.trace("Document {} to delete was not found on index '{}'", uid, getIndexName());
return false;
}
return true;
}
use of org.elasticsearch.action.delete.DeleteResponse in project opencast by opencast.
the class AbstractElasticsearchIndex method delete.
/**
* Removes the given document from the specified index.
*
* @param type
* the document type
* @param uid
* the identifier
* @return <code>true</code> if the element was found and deleted
* @throws SearchIndexException
* if deletion fails
*/
protected boolean delete(String type, String uid) throws SearchIndexException {
if (!preparedIndices.contains(index)) {
try {
createIndex(index);
} catch (IOException e) {
throw new SearchIndexException(e);
}
}
logger.debug("Removing element with id '{}' from searching index", uid);
DeleteRequestBuilder deleteRequest = nodeClient.prepareDelete(index, type, uid);
deleteRequest.setRefresh(true);
DeleteResponse delete = deleteRequest.execute().actionGet();
if (!delete.isFound()) {
logger.trace("Document {} to delete was not found", uid);
return false;
}
return true;
}
use of org.elasticsearch.action.delete.DeleteResponse in project wildfly-camel by wildfly-extras.
the class Elasticsearch5IntegrationTest method testGetSearchUpdateDelete.
@Test
public void testGetSearchUpdateDelete() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:index").to("elasticsearch5://elasticsearch?operation=INDEX&indexName=twitter&indexType=tweet&ip=localhost&port=" + ES_TRANSPORT_PORT);
from("direct:get").to("elasticsearch5://elasticsearch?operation=GET_BY_ID&indexName=twitter&indexType=tweet&ip=localhost&port=" + ES_TRANSPORT_PORT);
from("direct:search").to("elasticsearch5://elasticsearch?operation=SEARCH&indexName=twitter&indexType=tweet&ip=localhost&port=" + ES_TRANSPORT_PORT);
from("direct:update").to("elasticsearch5://elasticsearch?operation=UPDATE&indexName=twitter&indexType=tweet&ip=localhost&port=" + ES_TRANSPORT_PORT);
from("direct:delete").to("elasticsearch5://elasticsearch?operation=DELETE&indexName=twitter&indexType=tweet&ip=localhost&port=" + ES_TRANSPORT_PORT);
}
});
camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
// first, INDEX a value
Map<String, String> map = createIndexedData();
template.sendBody("direct:index", map);
String indexId = template.requestBody("direct:index", map, String.class);
Assert.assertNotNull("indexId should be set", indexId);
// now, verify GET succeeded
GetResponse getres = template.requestBody("direct:get", indexId, GetResponse.class);
Assert.assertNotNull("response should not be null", getres);
Assert.assertNotNull("response source should not be null", getres.getSource());
// now, verify GET succeeded
String query = "{\"query\":{\"match\":{\"content\":\"searchtest\"}}}";
SearchResponse searchres = template.requestBody("direct:search", query, SearchResponse.class);
Assert.assertNotNull("response should not be null", searchres);
Assert.assertNotNull("response hits should be == 1", searchres.getHits().totalHits());
Map<String, String> newMap = new HashMap<>();
newMap.put(createPrefix() + "key2", createPrefix() + "value2");
Map<String, Object> headers = new HashMap<>();
headers.put(ElasticsearchConstants.PARAM_INDEX_ID, indexId);
indexId = template.requestBodyAndHeaders("direct:update", newMap, headers, String.class);
Assert.assertNotNull("indexId should be set", indexId);
// now, perform DELETE
DeleteResponse delres = template.requestBody("direct:delete", indexId, DeleteResponse.class);
Assert.assertNotNull("response should not be null", delres);
// now, verify GET fails to find the indexed value
getres = template.requestBody("direct:get", indexId, GetResponse.class);
Assert.assertNotNull("response should not be null", getres);
Assert.assertNull("response source should be null", getres.getSource());
} finally {
camelctx.stop();
}
}
use of org.elasticsearch.action.delete.DeleteResponse in project kylo by Teradata.
the class IndexElasticSearchTest method cleanUp.
@After
public void cleanUp() {
DeleteResponse response = esClient.prepareDelete().setIndex(TEST_INDEX).setType(TEST_TYPE).setId("*").get();
esClient.close();
}
Aggregations