* Updates the specified objects
* @return the id's of the failed objects (e.g. due to versioning)
*/
public Collection<Integer> bulkUpdate(Collection<T> objects, String indexName, boolean refresh, boolean enableVersioning) {
// now using bulk API instead of feeding each doc separate with feedDoc
BulkRequestBuilder brb = client.prepareBulk();
// this works differently then the direct call to refresh!? maybe refresh is not async?
// brb.setRefresh(refresh);
for (T o : objects) {
if (o.getId() == null) {
logger.warn("Skipped object without id when bulkUpdate:" + o);
continue;
}
try {
XContentBuilder source = createDoc(o);
IndexRequest indexReq = Requests.indexRequest(indexName).type(getIndexType()).id(o.getId()).source(source);
if (enableVersioning)
indexReq.version(o.getVersion());
brb.add(indexReq);
} catch (IOException ex) {
logger.warn("Cannot add object:" + o + " to bulkIndexing action." + ex.getMessage());
}
}
if (brb.numberOfActions() > 0) {
BulkResponse rsp = brb.execute().actionGet();
if (rsp.hasFailures()) {
List<Integer> list = new ArrayList<Integer>(rsp.items().length);
for (BulkItemResponse br : rsp.items()) {
if(br.isFailed()) {
// logger.info("Error:" + br.failureMessage());