Index fails if field used for _parent in the script is ObjectId
mzafer opened this issue · 10 comments
Getting the below error if the _parent field used in river script is an objectid.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object 517749830364f0329c6c386f of class org.bson.types.ObjectId where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
[2013-06-05 23:03:49,885][WARN ][org.elasticsearch.river.mongodb.MongoDBRiver$Indexer] failed to execute bulk
org.elasticsearch.action.RoutingMissingException: routing is required for [authors]/[book]/[51774a210364f0329c6c387a]
In the extractParent (https://github.com/richardwilly98/elasticsearch-river-mongodb/blob/master/src/main/java/org/elasticsearch/river/mongodb/MongoDBRiver.java#L830 ) we'll have to check if the field is objectId, if so then it needs to be converted to string.
Can you please provide an example?
Thanks,
Richard.
Hi Richard,
We can recreate the issue using the files you have for #64 ( https://github.com/richardwilly98/elasticsearch-river-mongodb/tree/master/resources/issues/64 ), by replacing the content of " _03-import-document.js" to below.
use mydb
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)
Thanks
Zafer
Hi Richard,
A question unrelated to this issue. Any thoughts on how to change the format of the date fields before pushing to elasticsearch. I want to change the date to milliseconds format.
I tried the below script in my river definition, but it failed with the error "Rhino runtime detected object Sat Jun 15 19:12:20 EDT 2013 of class java.util.Date where it expected String, Number, Boolean or Scriptable instance." I thought RHINO will process that as the native Javascript Date object but it treats it as java Date.
"script": "ctx.document.created = new Date(ctx.document.created).getTime();"
Also for testing sake I hardcoded the numeric date value as below
"script": "ctx.document.created = 1371309235030;"
and it results in number getting changed to decimal format like below
{"created":1.37130923503E12}
Instead of
{"created":1366773205360}
Any thoughts for both the above issues - 1) Convert the ISO Date to millisecond format and 2 ) Not have he millisecond number into decimal format.
Google and Elastic search forums have not been of much help on this. Appreciate your help.
Thanks
Zafer
Thanks I thought about creating a separate issue but I asked here as it was more related to scripting than an issue with this plugin.
Also I have tested this _parent fix and it works.
Thanks much
Zafer
Fixed in release 1.6.9
Hi Richard,
Even though this issue is fixed, I notice that the warning is still occurring in the logs, yesterday when I tested I think I missed to see the warning message, I tested again with the 1.6.9 version and see the below message. The document is correctly indexed though
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object 51bfd41eb4fe203e853ef737 of class org.bson.types.ObjectId where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
[2013-06-17 23:32:45,721][INFO ][org.elasticsearch.river.mongodb.MongoDBRiver$Indexer] Indexed 1 documents, 1 insertions 0, updates, 0 deletions, 0 documents per second
[2013-06-17 23:32:45,722][INFO ][cluster.metadata ] [omm-node1] [authors] update_mapping book
[2013-06-17 23:32:45,727][INFO ][cluster.metadata ] [omm-node1] [_river] update_mapping books85
Thanks
Zafer
Hi Zafer,
Unfortunately this warning seems to be specific to elasticsearch/elasticsearch-lang-javascript plugin. A DBObject object is passed to Rhino it should be wrapped by the plugin using as suggested Context.javaToJS.
So I will not be able to fix it from the river.
I believe using Groovy script if your javascript becomes complex might be a good option.
Thanks,
Richard.
It is wierd that a DBObject is being passed even after converting to String. But thanks for looking, I can live with the warning for now and if it gets worse then I'll look into Context.javaToJS or Groovy script.
Thanks