Skip to content
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

Index fails if field used for _parent in the script is ObjectId #85

Closed
mzafer opened this issue Jun 6, 2013 · 10 comments
Closed

Index fails if field used for _parent in the script is ObjectId #85

mzafer opened this issue Jun 6, 2013 · 10 comments

Comments

@mzafer
Copy link

mzafer commented Jun 6, 2013

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.

@richardwilly98
Copy link
Owner

Can you please provide an example?

Thanks,
Richard.

@mzafer
Copy link
Author

mzafer commented Jun 12, 2013

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

@mzafer
Copy link
Author

mzafer commented Jun 16, 2013

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

richardwilly98 added a commit that referenced this issue Jun 16, 2013
All extract methods will call toString method if the object is not null.
@richardwilly98
Copy link
Owner

@mzafer I have create a new issuer [1] from your last comment as it is unrelated.

[1] - issue #90

@mzafer
Copy link
Author

mzafer commented Jun 16, 2013

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

@mzafer mzafer closed this as completed Jun 16, 2013
@richardwilly98
Copy link
Owner

Fixed in release 1.6.9

@mzafer
Copy link
Author

mzafer commented Jun 18, 2013

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

@richardwilly98
Copy link
Owner

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.

@mzafer
Copy link
Author

mzafer commented Jun 25, 2013

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

@richardwilly98
Copy link
Owner

@mzafer I will close this issue but create a new for the warning with Context.javaToJS #148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants