An Elastic document has a structure like this:
...
"somefield": "somevalue",
"orders": [{
"version": 1,
"statusCode": 1
}, {
"version": 1,
"statusCode": 1
}, {
"version": 2,
"statusCode": 2
}, {
"version": 3,
"statusCode": 5
}, {
"version": 3,
"statusCode": 6
}
]
...
"orders" is a nested list. I use inline sctipting to calculate the size of the list like this:
"params._source.orders.size() < 4"
I have to add a condition to calculate the number of orders whose statusCode is not 5 and not 6. Linq would look like this:
...orders.Where(o=>!(new[] {5, 6}).Contains(o.statusCode)).size()...
How to write the script in Painless or Groovy?
This results an exeption:
params._source.orders.count { it -> it.statusCode == 1 } < 4