logger.trace("Insert operation - id: {} - contains attachment: {}", objectId, (data instanceof GridFSDBFile)); getBulkProcessor(index, type).addBulkRequest(objectId, build(data, objectId), routing, parent); logger.trace("Update operation - id: {} - contains attachment: {}", objectId, (data instanceof GridFSDBFile)); deleteBulkRequest(objectId, index, type, routing, parent); getBulkProcessor(index, type).addBulkRequest(objectId, build(data, objectId), routing, parent); deleteBulkRequest(objectId, index, type, routing, parent); MongoDBRiverBulkProcessor processor = getBulkProcessor(index, type); processor.dropIndex(); } else {
/** * Map a DBObject for indexing * * @param dbObj */ private Map<String, Object> createObjectMap(DBObject dbObj) { Map<String, Object> mapData = new HashMap<String, Object>(); for (String key : dbObj.keySet()) { Object value = dbObj.get(key); if (value instanceof DBRef) { mapData.put(key, this.convertDbRef((DBRef) value)); } else if (value instanceof BasicDBList) { mapData.put(key, ((BasicBSONList) value).toArray()); } else if (value instanceof BasicDBObject) { mapData.put(key, this.createObjectMap((DBObject) value)); } else { mapData.put(key, value); } } return mapData; }
Map<String, Object> document = new HashMap<String, Object>(); if (hasScript()) { if (ctx != null && documents != null) { logger.trace("item: {}", item); if (isDocumentDeleted(item)) { item.put("operation", MongoDBRiver.OPLOG_DELETE_OPERATION); String index = extractIndex(item); type = extractType(item, type); String parent = extractParent(item); String routing = extractRouting(item); operation = extractOperation(item); boolean ignore = isDocumentIgnored(item); Map<String, Object> data = (Map<String, Object>) item.get("data"); objectId = extractObjectId(data, objectId); if (logger.isTraceEnabled()) { logger.trace( updateBulkRequest(new BasicDBObject(data), objectId, operation, index, type, routing, parent); } catch (IOException ioEx) { logger.error("Update bulk failed.", ioEx);
private XContentBuilder build(final DBObject data, final String objectId) throws IOException { if (data instanceof GridFSDBFile) { logger.info("Add Attachment: {} to index {} / type {}", objectId, definition.getIndexName(), definition.getTypeName()); return MongoDBHelper.serialize((GridFSDBFile) data); } else { Map<String, Object> mapData = this.createObjectMap(data); return XContentFactory.jsonBuilder().map(mapData); } }
new Indexer(MongoDBRiver.this)); indexerThread.start();
updateBulkRequest(entry.getData(), null, operation, definition.getIndexName(), type, null, null); } catch (IOException ioEx) { logger.error("Update bulk failed.", ioEx); updateBulkRequest(entry.getData(), objectId, operation, definition.getIndexName(), type, null, null); } catch (IOException ioEx) { logger.error("Update bulk failed.", ioEx); if (hasScript() && definition.isAdvancedTransformation()) { return applyAdvancedTransformation(entry, type); if (hasScript()) { if (ctx != null) { ctx.put("document", entry.getData()); if (isDocumentIgnored(ctx)) { logger.trace("From script ignore document id: {}", objectId); if (isDocumentDeleted(ctx)) { ctx.put("operation", MongoDBRiver.OPLOG_DELETE_OPERATION); operation = extractOperation(ctx); logger.trace("From script operation: {} -> {}", ctx.get("operation").toString(), operation); String index = extractIndex(ctx); type = extractType(ctx, type); String parent = extractParent(ctx); String routing = extractRouting(ctx); objectId = extractObjectId(ctx, objectId);