Search code examples
elasticsearchgroovymvel

Error translating mvel script to groovy


While preparing for an update to elasticsearch 2.0, I noticed mvel scripting is being deprecated in favor of groovy. My problem is that I am new to groovy and don't know how to fix this error.

boolean engineTest = false; if (!engineTest) { engineTest = true;} return engineTest;

This throws the following error

unexpected token: return @ line 1, column 68. [...]

Solution

  • If it all needs to be on 1 line, then you're missing a semi-colon before the return statement. As in:

    ​boolean engineTest = false; if (!engineTest) { engineTest = true}; return engineTest;​
    

    Otherwise, you could split the statements on 3 lines and avoid all semi-colons.