Skip to content

Commit

Permalink
Fix for issue #105
Browse files Browse the repository at this point in the history
  • Loading branch information
richardwilly98 committed Jul 30, 2013
1 parent b482776 commit 5d70e12
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 15 deletions.
4 changes: 4 additions & 0 deletions resources/issues/105/01_create-river.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
curl -XPUT "http://localhost:9200/mydb105" -d @disabled-mapping.json
curl -XPUT "http://localhost:9200/mydb105/document/_mapping" -d @custom-mapping.json
pause
curl -XPUT "http://localhost:9200/_river/river105/_meta" -d @mongodb-river-simple.json
7 changes: 7 additions & 0 deletions resources/issues/105/02_test-issue-105.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
%MONGO_HOME%\bin\mongo < test-issue-105.js
pause
curl -XGET localhost:9200/mydb105/_search?pretty=true&q=firstName:John
pause
%MONGO_HOME%\bin\mongo < drop-collection-105.js
pause
curl -XGET localhost:9200/mydb105/_mapping?pretty=true
19 changes: 19 additions & 0 deletions resources/issues/105/custom-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"document": {
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"nickName": {
"type": "string", "index":"not_analyzed"
},
"creationDate": {
"type": "date",
"format": "dateOptionalTime"
}
}
}
}
3 changes: 3 additions & 0 deletions resources/issues/105/disabled-mapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"index.mapper.dynamic": false
}
2 changes: 2 additions & 0 deletions resources/issues/105/drop-collection-105.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use mydb105
db.document.drop()
14 changes: 14 additions & 0 deletions resources/issues/105/mongodb-river-simple.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"type": "mongodb",
"mongodb": {
"db": "mydb105",
"collection": "document",
"options": {
"drop_collection": true
}
},
"index": {
"name": "mydb105",
"type": "document"
}
}
10 changes: 10 additions & 0 deletions resources/issues/105/test-issue-105.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use mydb105
var o =
{
"firstName": "John",
"lastName": "Doe",
"nickName": "The Boss",
"creationDate": "2013-06-11T12:00:00.0000-04:00"
}

db.document.save(o)
30 changes: 15 additions & 15 deletions src/main/java/org/elasticsearch/river/mongodb/MongoDBRiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@
import org.bson.types.ObjectId;
import org.elasticsearch.ElasticSearchInterruptedException;
import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingResponse;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.delete.DeleteRequest;
Expand Down Expand Up @@ -884,6 +883,8 @@ private BSONTimestamp updateBulkRequest(final BulkRequestBuilder bulk,
.admin().cluster().prepareState().execute()
.actionGet().getState().getMetaData()
.index(index).mappings();
logger.trace("mappings contains type {}: {}", type,
mappings.containsKey(type));
if (mappings.containsKey(type)) {
/*
* Issue #105 - Mapping changing from custom
Expand All @@ -893,16 +894,15 @@ private BSONTimestamp updateBulkRequest(final BulkRequestBuilder bulk,
* before to delete.
*/
MappingMetaData mapping = mappings.get(type);
DeleteMappingRequest deleteMappingRequest = new DeleteMappingRequest(
index);
deleteMappingRequest.type(type);
client.admin().indices()
.deleteMapping(deleteMappingRequest);
PutMappingRequest putMapping = new PutMappingRequest(
index);
putMapping.type(type);
putMapping.source(mapping.getSourceAsMap());
client.admin().indices().putMapping(putMapping);
client.admin().indices().prepareDeleteMapping(index).setType(type).execute().actionGet();
PutMappingResponse pmr = client.admin()
.indices().preparePutMapping(index)
.setType(type)
.setSource(mapping.source().string())
.execute().actionGet();
if (!pmr.isAcknowledged()) {
logger.error("Failed to put mapping {} / {} / {}.", index, type, mapping.source());
}
}

deletedDocuments = 0;
Expand Down Expand Up @@ -1204,8 +1204,8 @@ private void processOplogEntry(final DBObject entry)
throw new NullPointerException(MONGODB_ID_FIELD);
}
logger.info("Add attachment: {}", objectId);
object = MongoDBHelper.applyExcludeFields(object,
excludeFields);
object = MongoDBHelper
.applyExcludeFields(object, excludeFields);
HashMap<String, Object> data = new HashMap<String, Object>();
data.put(IS_MONGODB_ATTACHMENT, true);
data.put(MONGODB_ATTACHMENT, object);
Expand Down Expand Up @@ -1324,7 +1324,7 @@ private void addQueryToStream(final String operation,
"addQueryToStream - operation [{}], currentTimestamp [{}], update [{}]",
operation, currentTimestamp, update);
}

for (DBObject item : slurpedCollection.find(update, findKeys)) {
addToStream(operation, currentTimestamp, item.toMap());
}
Expand Down

1 comment on commit 5d70e12

@buildhive
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Richard Louapre » elasticsearch-river-mongodb #57 UNSTABLE
Looks like this commit caused a build failure
(what's this?)

Please sign in to comment.