JVK JVK - 1 month ago 5
Groovy Question

Syntax error in groovy script - what is wrong?

I am trying to execute the following groovy script snippet in my elasticsearch dsl scripting:

[doc['availabilities.start'], doc['availabilities.end']].transpose().any { (start, end) -> end.date.getMillis() >= 11 } return 2;

```

and this throws the following error
enter image description here

I am pretty new in Groovy and unable to figure out what is the wrong syntax here. Any help will be appreciated.

Answer

Groovy doesn't use parentheses around closure parameters, so that should be

.any { start, end -> end.date.getMillis() >= 11 }

And return 2; at the end discards the result of the previous expression, I'm not sure if that was your intention.

Comments