Skip to content

getSourceAsString() for doc inserted as SMILE fails, auto convert to JSON #2064

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

Closed
andrewclegg opened this issue Jun 28, 2012 · 4 comments
Closed

Comments

@andrewclegg
Copy link

In a unit test, I have a document containing one field "val" which is a list of floats:

{ Float.MIN_VALUE, Float.MIN_VALUE - 1, Float.MAX_VALUE, -Float.MIN_VALUE }

The JSON representation of this is:

{"val":[1.4E-45,-1.0,3.4028235E38,-1.4E-45]}

getSourceAsString() on the corresponding GetResponse object returns this successfully when I inserted the document using XContentFactory.jsonBuilder(), but when I inserted the document using XContentFactory.smileBuilder(), I got:

java.lang.ArrayIndexOutOfBoundsException: 87
at org.elasticsearch.common.Unicode.UTF8toUTF16(Unicode.java:190)
at org.elasticsearch.common.Unicode.unsafeFromBytesAsUtf16(Unicode.java:106)
at org.elasticsearch.common.Unicode.fromBytes(Unicode.java:80)
at org.elasticsearch.index.get.GetResult.sourceAsString(GetResult.java:203)
at org.elasticsearch.action.get.GetResponse.sourceAsString(GetResponse.java:150)
...

Will attach a demonstration case when I have a chance.

@kimchy
Copy link
Member

kimchy commented Jun 28, 2012

Yea, that will happen..., wondering what should be done here, obviously, smile can't be converted to string, maybe we should do auto conversion to json and then return it as string?

@andrewclegg
Copy link
Author

Aaah okay. Won't need a demo case if it's known behaviour :-)

Auto conversion would work (if it's not super heavyweight?), but even some sort of NotSupportedException that told you you couldn't do this with SMILE docs would be useful.

@kimchy
Copy link
Member

kimchy commented Jun 28, 2012

I think I will add auto conversion, in any case, you are usually better off using the bytes and not the string itself in your app.

@andrewclegg
Copy link
Author

We're not actually even using the source, this was just in a defunct test that died when I switched to SMILE. Thanks for quick feedback!

@kimchy kimchy closed this as completed in 0745424 Jun 28, 2012
hibnico pushed a commit to hibnico/elasticsearch that referenced this issue Jul 6, 2012
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants