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

Transport exception processing BigDecimal type from groovy script #11071

Closed
bradvido opened this issue May 8, 2015 · 10 comments
Closed

Transport exception processing BigDecimal type from groovy script #11071

bradvido opened this issue May 8, 2015 · 10 comments
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache discuss

Comments

@bradvido
Copy link
Contributor

bradvido commented May 8, 2015

I'm using ElasticSearch 1.5.2.

I have a groovy script_file
disk_total_free_percent.groovy:

def totalSize = doc['Machine.disk_total_size_(mb)'].value;
def freeSpace = doc['Machine.disk_total_free_space_(mb)'].value;
if(totalSize == 0) { 
    //none is free, since the disk has no size
    0.0 //percent
}else {
    freeSpace / totalSize   
}

When I execute a search with script_fields including the above script, I get an error from ES
[indices:data/read/search[phase/fetch/id]]]; nested: IOException[Can't write type [class java.math.BigDecimal]];
This is generated by this line of code in StreamOutput.java

It's also interesting that the number of shards that fail with this exception varies (for the same query). Sometimes it's 1, sometimes 2 or 3.


For comparison, I installed the javascript scripting plugin and tried the same script (replacing def with var)
disk_total_free_percent.js:

var totalSize = doc['Machine.disk_total_size_(mb)'].value;
var freeSpace = doc['Machine.disk_total_free_space_(mb)'].value;
if(totalSize == 0) { 
    //none is free, since the disk has no size
    0.0 //percent
}else {
    freeSpace / totalSize   
}

And it worked without any exceptions. This makes me think it's a problem with the Groovy scripting module.

@clintongormley clintongormley added >bug help wanted adoptme :Core/Infra/Scripting Scripting abstractions, Painless, and Mustache and removed help wanted adoptme >bug labels May 15, 2015
@clintongormley
Copy link

@bradvido I've tried various combinations of mappings etc to replicate this problem on 1.5.2, and it all seems to work just fine. Could you add a small recreation?

For some reason Groovy is converting one of those values to BigDecimal (which we don't support), but I can't see why it is doing that. I found this bug which may be related? http://jira.codehaus.org/browse/GROOVY-7238

@bradvido
Copy link
Contributor Author

I should mention I'm running ES on Windows -- maybe the bug is platform specific,

Also, in Groovy, every literal number with a decimal point becomes a BigDecimal. It needs a 'd' identifier to be treated as a double.

So maybe, i should change the literal 0.0 to 0.0d in my script? I'll test when I have time to get back to this.

@dakrone
Copy link
Member

dakrone commented May 15, 2015

We automatically convert BigDecimal constants to floating-point, see here: #6609

@bradvido
Copy link
Contributor Author

Hmm, then it shouldn't make a difference if i use literal decimals in my script. I'll try to find a simple way so others can reproduce this.

@fredrlx
Copy link

fredrlx commented Jun 17, 2015

Hi! I've run into a similar issue (same "Can't write type [class java.math.BigDecimal]" exception on some shards). Our groovy script had this line:

s = round(s*100)/100; 

rewriting it to the following got rid of the exception:

s = round(s*100d)/100d; 

@bradvido
Copy link
Contributor Author

@fredrlx what version of ES & Groovy are you using? #6609 should have already take care of this, but I've seen similar results.

@fredrlx
Copy link

fredrlx commented Jun 22, 2015

@bradvido We were using ES 1.5.1 when we had this issue. How do I check what version of Groovy I have ? I'll update ES to a more recent version, but the issue was solved with the "d" postfix on constants.

@clintongormley
Copy link

This should be fixed by #12288 - I'm going to close for now, but feel free to reopen if you see the same thing on 1.7.0 or later

thaks

@bradvido
Copy link
Contributor Author

Thanks. Will test on 1.7.0

@mausch
Copy link

mausch commented Aug 24, 2016

Just hit this issue in 1.7.2. I know this is an old issue and an old version of ES, just wanted to say for future reference that changing an expression from xxx.sum(0) to xxx.sum(0d) as suggested above did the trick.
Also, this only happened in a script_fields script. The same script did not crash as a function_score.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/Scripting Scripting abstractions, Painless, and Mustache discuss
Projects
None yet
Development

No branches or pull requests

5 participants