Skip to content

fix for excludeFields property does not work for update operations #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 29, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/org/elasticsearch/river/mongodb/MongoDBRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public class MongoDBRiver extends AbstractRiverComponent implements River {
protected final TimeValue bulkTimeout;
protected final int throttleSize;
protected final boolean dropCollection;
protected final Set<String> excludeFields;
protected final BasicDBObject excludeFields;

private final ExecutableScript script;

Expand Down Expand Up @@ -270,7 +270,7 @@ public MongoDBRiver(final RiverName riverName,
mongoOptionsSettings.get(SSL_VERIFY_CERT_FIELD), true);

if (mongoOptionsSettings.containsKey(EXCLUDE_FIELDS_FIELD)) {
excludeFields = new HashSet<String>();
excludeFields = new BasicDBObject();
Object excludeFieldsSettings = mongoOptionsSettings
.get(EXCLUDE_FIELDS_FIELD);
logger.info("excludeFieldsSettings: "
Expand All @@ -282,7 +282,7 @@ public MongoDBRiver(final RiverName riverName,
ArrayList<String> fields = (ArrayList<String>) excludeFieldsSettings;
for (String field : fields) {
logger.info("Field: " + field);
excludeFields.add(field);
excludeFields.put(field,0);
}
}
} else {
Expand Down Expand Up @@ -944,7 +944,7 @@ private void logStatistics() {
long totalDocumentsPerSecond = (totalTimeInSeconds == 0) ? totalDocuments
: totalDocuments / totalTimeInSeconds;
logger.info(
"Indexed {} documents, {} insertions {}, updates, {} deletions, {} documents per second",
"Indexed {} documents, {} insertions, {} updates, {} deletions, {} documents per second",
totalDocuments, insertedDocuments, updatedDocuments,
deletedDocuments, totalDocumentsPerSecond);
}
Expand Down Expand Up @@ -1115,8 +1115,6 @@ private void processOplogEntry(final DBObject entry)
object.toString());
}

object = MongoDBHelper.applyExcludeFields(object, excludeFields);

// Initial support for sharded collection -
// https://jira.mongodb.org/browse/SERVER-4333
// Not interested in operation from migration or sharding
Expand Down Expand Up @@ -1162,6 +1160,7 @@ private void processOplogEntry(final DBObject entry)
throw new NullPointerException(MONGODB_ID_FIELD);
}
logger.info("Add attachment: {}", objectId);
object = MongoDBHelper.applyExcludeFields(object, excludeFields.keySet());
HashMap<String, Object> data = new HashMap<String, Object>();
data.put(IS_MONGODB_ATTACHMENT, true);
data.put(MONGODB_ATTACHMENT, object);
Expand All @@ -1173,6 +1172,7 @@ private void processOplogEntry(final DBObject entry)
logger.debug("Updated item: {}", update);
addQueryToStream(operation, oplogTimestamp, update);
} else {
object = MongoDBHelper.applyExcludeFields(object, excludeFields.keySet());
addToStream(operation, oplogTimestamp, object.toMap());
}
}
Expand Down Expand Up @@ -1278,7 +1278,7 @@ private void addQueryToStream(final String operation,
"addQueryToStream - operation [{}], currentTimestamp [{}], update [{}]",
operation, currentTimestamp, update);
}
for (DBObject item : slurpedCollection.find(update)) {
for (DBObject item : slurpedCollection.find(update,excludeFields)) {
addToStream(operation, currentTimestamp, item.toMap());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.gridfs.GridFSDBFile;

Expand Down