简体   繁体   中英

Spring data elasticsearch bulk index and delete

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM