Skip to content

Commit

Permalink
Fix for issue #85
Browse files Browse the repository at this point in the history
All extract methods will call toString method if the object is not null.
  • Loading branch information
richardwilly98 committed Jun 16, 2013
1 parent 5d40d19 commit 27946ed
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 8 deletions.
28 changes: 28 additions & 0 deletions resources/issues/85/$ES_HOME/config/templates/template_1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"template_1" : {
"template" : "authors*",
"settings" : {
"number_of_shards" : 1,
"mapper" : {
"dynamic": false
}
},
"mappings" : {
"author": {
"properties": {
"name": {
"type": "string"
},
"nationality": {
"type": "string"
}
}
},
"book": {
"_parent": {
"type": "author"
}
}
}
}
}
1 change: 1 addition & 0 deletions resources/issues/85/01_create-index-with-mapping.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -XPUT "http://localhost:9200/authors" -d @_01_create-index-with-mapping.json
3 changes: 3 additions & 0 deletions resources/issues/85/02_create-river.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
curl -XPUT "http://localhost:9200/_river/authors85/_meta" -d @_02_mongodb-river-author.json
PAUSE
curl -XPUT "http://localhost:9200/_river/books85/_meta" -d @_02_mongodb-river-book.json
4 changes: 4 additions & 0 deletions resources/issues/85/03_test-issue-85.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
%MONGO_HOME%\bin\mongo < _03-import-document.js
pause
curl -XPOST "localhost:9200/authors/author/_search?pretty=true" -d @_03-has-child-query.json
pause
25 changes: 25 additions & 0 deletions resources/issues/85/_01_create-index-with-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"settings" : {
"number_of_shards" : 1,
"mapper" : {
"dynamic": false
}
},
"mappings" : {
"author": {
"properties": {
"name": {
"type": "string"
},
"nationality": {
"type": "string"
}
}
},
"book": {
"_parent": {
"type": "author"
}
}
}
}
11 changes: 11 additions & 0 deletions resources/issues/85/_02_mongodb-river-author.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"type": "mongodb",
"mongodb": {
"db": "mydb85",
"collection": "authors"
},
"index": {
"name": "authors",
"type": "author"
}
}
12 changes: 12 additions & 0 deletions resources/issues/85/_02_mongodb-river-book.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "mongodb",
"mongodb": {
"db": "mydb85",
"collection": "books",
"script": "if(ctx.document._parentId) { ctx._parent = ctx.document._parentId; delete ctx.document._parentId;}"
},
"index": {
"name": "authors",
"type": "book"
}
}
19 changes: 19 additions & 0 deletions resources/issues/85/_03-has-child-query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"query": {
"has_child": {
"type": "book",
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"term": {
"publisher": "Herge"
}
}
}
}
}
}
}
20 changes: 20 additions & 0 deletions resources/issues/85/_03-import-document.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use mydb85

var author =
{
"name": "Herge",
"nationality": "Belge"
}

db.authors.save(author)

var author1 = db.authors.findOne()

var book = {
"_parentId": author1._id,
"name": "Titin au Congo",
"genre": "Bande dessinee",
"publisher": "Herge"
}

db.books.save(book)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"%MONGO_HOME%\bin\mongo.exe" --host localhost --port 27017 --shell create-replicaset.js
9 changes: 9 additions & 0 deletions resources/issues/85/simple-replicaset/create-replicaset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var adminDb;
function createReplicaset() {
var config = { _id: "replica1", members:[{ _id : 0, host : "localhost:27017" }, { _id : 1, host : "localhost:27018" }, { _id : 2, host : "localhost:27019" }]};
var cmd = {"replSetInitiate": config};
adminDb.runCommand(cmd);
//rs.status();
}
adminDb = db.getSiblingDB("admin");
createReplicaset();
3 changes: 3 additions & 0 deletions resources/issues/85/simple-replicaset/mongo-node-1.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET DB_PATH="D:\data\mongodb\rep1-db1"
mkdir %DB_PATH%
"%MONGO_HOME%\bin\mongod.exe" --replSet replica1 --port 27017 --dbpath %DB_PATH% --rest --oplogSize 100
3 changes: 3 additions & 0 deletions resources/issues/85/simple-replicaset/mongo-node-2.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET DB_PATH="D:\data\mongodb\rep1-db2"
mkdir %DB_PATH%
"%MONGO_HOME%\bin\mongod.exe" --replSet replica1 --port 27018 --dbpath %DB_PATH% --rest --oplogSize 100
3 changes: 3 additions & 0 deletions resources/issues/85/simple-replicaset/mongo-node-3.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET DB_PATH="D:\data\mongodb\rep1-db3"
mkdir %DB_PATH%
"%MONGO_HOME%\bin\mongod.exe" --replSet replica1 --port 27019 --dbpath %DB_PATH% --rest --oplogSize 100
5 changes: 5 additions & 0 deletions resources/issues/85/simple-replicaset/start-replicaset.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
start "replica node #1" mongo-node-1.bat
start "replica node #2" mongo-node-2.bat
start "replica node #3" mongo-node-3.bat
sleep 10
REM start "mongos - port 37017" mongos-node-0.bat
32 changes: 24 additions & 8 deletions src/main/java/org/elasticsearch/river/mongodb/MongoDBRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -827,27 +827,39 @@ private XContentBuilder build(final Map<String, Object> data,
}

private String extractObjectId(Map<String, Object> ctx, String objectId) {
String id = (String) ctx.get("id");
Object id = ctx.get("id");
if (id == null) {
id = objectId;
return objectId;
} else {
return id.toString();
}
return id;
}

private String extractParent(Map<String, Object> ctx) {
return (String) ctx.get("_parent");
Object parent = ctx.get("_parent");
if (parent == null) {
return null;
} else {
return parent.toString();
}
}

private String extractRouting(Map<String, Object> ctx) {
return (String) ctx.get("_routing");
Object routing = ctx.get("_routing");
if (routing == null) {
return null;
} else {
return routing.toString();
}
}

private String extractType(Map<String, Object> ctx) {
String type = (String) ctx.get("_type");
Object type = ctx.get("_type");
if (type == null) {
type = typeName;
return typeName;
} else {
return type.toString();
}
return type;
}

private String extractIndex(Map<String, Object> ctx) {
Expand Down Expand Up @@ -1020,6 +1032,10 @@ private void processOplogEntry(final DBObject entry)
BSONTimestamp oplogTimestamp = (BSONTimestamp) entry
.get(OPLOG_TIMESTAMP);
DBObject object = (DBObject) entry.get(OPLOG_OBJECT);

if (logger.isTraceEnabled()) {
logger.trace("MongoDB object deserialized: {}", object.toString());
}

object = MongoDBHelper.applyExcludeFields(object, excludeFields);
// if (excludeFields != null) {
Expand Down

0 comments on commit 27946ed

Please sign in to comment.