Spring data elasticsearch bulk index and delete
Asked Answered
E

1

14

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?

Eternity answered 28/5, 2017 at 11:31 Comment(0)
C
0

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.

Conferral answered 25/3, 2020 at 17:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.