Reputation: 151
I'm new to the community so I apologise if I do something wrong.
I'm using spring data elasticsearch (2.0.4/2.4) And I would like to make a bulk insert and delete. But ElasticsearchTemplate only contains a method bulkInsert
@Override
public void bulkIndex(List<IndexQuery> queries) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (IndexQuery query : queries) {
bulkRequest.add(prepareIndex(query));
}
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
Map<String, String> failedDocuments = new HashMap<String, String>();
for (BulkItemResponse item : bulkResponse.getItems()) {
if (item.isFailed())
failedDocuments.put(item.getId(), item.getFailureMessage());
}
throw new ElasticsearchException(
"Bulk indexing has failures. Use ElasticsearchException.getFailedDocuments() for detailed messages ["
+ failedDocuments + "]", failedDocuments
);
}
}
So I have created a bulk method to handle both but I can't access the method prepareIndex which is private.
Are you aware of any solution to, in one bulk, index and delete documents or should I use reflection to change visibility of the prepareIndex method or is there any easy way to create an indexRequest from a model/POJO?
Upvotes: 15
Views: 4527
Reputation: 1553
it depends of elastic version. For last version of elastic you can use "Delete by query API"
Deletes documents that match the specified query.
https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-delete-by-query.html
Upvotes: 0
Reputation: 19471
Not sure which versions you mean with
(2.0.4/2.4)
Currently there is no possibility for bulk deletes. And no combination of different operations like index/update in one request.
Can you file an issue in Jira to add support for bulk delete and a possibility to have different operations in one call? Though this won't make it into the next release, I'm afraid.
Upvotes: 0