Skip to content
This repository was archived by the owner on May 18, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ void deleteIndex(String indexName) {
void bulkIndex(Collection<IndexRequest> 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";
Expand Down Expand Up @@ -221,6 +221,16 @@ List<String> fetchAllDocuments(String routing, String... indices) {
}
}

void deleteAllDocuments(String... indices) {
List<String> documents = fetchAllDocuments(indices);
documents.forEach(this::deleteIndex);
}

void deleteAllDocuments(String routing, String... indices) {
List<String> documents = fetchAllDocuments(routing, indices);
documents.forEach(this::deleteIndex);
}

private Stream<String> searchForDocuments(Optional<String> indexMaybe) {
return searchForDocuments(indexMaybe, Optional.empty());
}
Expand Down