Hi,
I have an array that contains some bucket keys. i want to do something for each bucket if their key is in my array.
here is my code so far:
"script": {
"source": """
def docs = [];
def removes=ctx.payload.aggregations.event_types.buckets.remove.users.buckets.stream().map(p -> p.key).collect(Collectors.toList());
def logins=ctx.payload.aggregations.event_types.buckets.login.users.buckets.stream().map(p -> p.key).collect(Collectors.toList());
def hits = ctx.payload.aggregations.event_types.buckets.add.users.buckets;
def user = ctx.payload.aggregations.event_types.buckets.add.users.buckets.stream().map(u -> u.key).filter(u -> removes.contains(u)).filter(u -> logins.contains(u)).toArray();
for (hit in hits){
if (user.values.contains(hit.key)){
def document = [
///DO SOMETHING..
];
docs.add(document);
}
}
return ['_doc':docs];
""",
"lang": "painless"
}
But I just can't figure out how to check the condition for that ( check if bucket keys exist in user array)
thanks