@Test void testDeleteResourceNotFound() { Index index = Index.create("index"); when(document.getId()).thenReturn("id"); when(client.prepareDelete()).thenReturn(deleteRequestBuilder); when(deleteRequestBuilder.setIndex("index")).thenReturn(deleteRequestBuilder); when(deleteRequestBuilder.setType(any())).thenReturn(deleteRequestBuilder); when(deleteRequestBuilder.setId("id")).thenReturn(deleteRequestBuilder); when(deleteRequestBuilder.get()).thenThrow(new ResourceNotFoundException("exception")); Exception exception = assertThrows(UnknownIndexException.class, () -> clientFacade.deleteById(index, document)); assertThat(exception.getMessage()).containsPattern("Index 'index' not found\\."); }
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()); } }
ClientFacade implements Closeable { 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()); } } }
ClientFacade implements Closeable { 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()); } } ClientFacade(Client client); }
ClientFacade implements Closeable { 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()); } } ClientFacade(Client client); void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream); boolean indexesExist(Index index); void deleteIndex(Index index); void refreshIndexes(); long getCount(Index index); long getCount(QueryBuilder query, Index index); SearchHits search(QueryBuilder query, int from, int size, List<Index> indexes); SearchHits search(QueryBuilder query, int from, int size, Sort sort, Index index); Aggregations aggregate(
      List<AggregationBuilder> aggregations, QueryBuilder query, Index index); Explanation explain(SearchHit searchHit, QueryBuilder query); void index(Index index, Document document); void deleteById(Index index, Document document); void processDocumentActions(Stream<DocumentAction> documentActions); @Override void close(); }
ClientFacade implements Closeable { 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()); } } ClientFacade(Client client); void createIndex(Index index, IndexSettings indexSettings, Stream<Mapping> mappingStream); boolean indexesExist(Index index); void deleteIndex(Index index); void refreshIndexes(); long getCount(Index index); long getCount(QueryBuilder query, Index index); SearchHits search(QueryBuilder query, int from, int size, List<Index> indexes); SearchHits search(QueryBuilder query, int from, int size, Sort sort, Index index); Aggregations aggregate(
      List<AggregationBuilder> aggregations, QueryBuilder query, Index index); Explanation explain(SearchHit searchHit, QueryBuilder query); void index(Index index, Document document); void deleteById(Index index, Document document); void processDocumentActions(Stream<DocumentAction> documentActions); @Override void close();  }