diff --git a/README.md b/README.md index e0ce191..4ef2893 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,7 @@ Availabe `JavaHomeOption` options | `stop()` | stops your Elasticsearch instance and removes all data | | `index` | index your document, comes with variants that take only document, or document and it's id | | `deleteIndex(String indexName)`, `deleteIndices()` | deletes index with name specified during EmbeddedElastic creation | +| `deleteAllDocuments(String indexName)`, `deleteAllDocuments(String routing, String indexName)` | deletes all documents with name specified index name or specified routing and index name during EmbeddedElastic creation | | `createIndex(String indexName)`, `createIndices()` | creates index with name specified during EmbeddedElastic creation; note that this index is created during EmbeddedElastic startup, you will need this method only if you deleted your index using `deleteIndex` method | | `recreateIndex(String indexName)`, `recreateIndices()` | combination of `deleteIndex` and `createIndex` | | `refreshIndices()` | refresh index; useful when you make changes in different thread, and want to check results instantly in tests | diff --git a/core/src/main/java/pl/allegro/tech/embeddedelasticsearch/ElasticRestClient.java b/core/src/main/java/pl/allegro/tech/embeddedelasticsearch/ElasticRestClient.java index 1f2b88a..48d2c9a 100644 --- a/core/src/main/java/pl/allegro/tech/embeddedelasticsearch/ElasticRestClient.java +++ b/core/src/main/java/pl/allegro/tech/embeddedelasticsearch/ElasticRestClient.java @@ -138,10 +138,10 @@ void deleteIndex(String indexName) { void bulkIndex(Collection indexRequests) { String bulkRequestBody = indexRequests.stream() .flatMap(request -> - Stream.of( - indexMetadataJson(request.getIndexName(), request.getIndexType(), request.getId(), request.getRouting()), - request.getJson() - ) + Stream.of( + indexMetadataJson(request.getIndexName(), request.getIndexType(), request.getId(), request.getRouting()), + request.getJson() + ) ) .map((jsonNodes) -> jsonNodes.replace('\n', ' ').replace('\r', ' ')) .collect(joining("\n")) + "\n"; @@ -221,6 +221,16 @@ List fetchAllDocuments(String routing, String... indices) { } } + void deleteAllDocuments(String... indices) { + List documents = fetchAllDocuments(indices); + documents.forEach(this::deleteIndex); + } + + void deleteAllDocuments(String routing, String... indices) { + List documents = fetchAllDocuments(routing, indices); + documents.forEach(this::deleteIndex); + } + private Stream searchForDocuments(Optional indexMaybe) { return searchForDocuments(indexMaybe, Optional.empty()); }