Question
I am chaining different elasticsearch queries in a watcher. I short I'd like to do this:
- find container_ids
- run a query on all entries with any of those container_ids
the first query gives me an array. So I would like to pass that array as an input to the terms query. Trouble is that the ctx.payload... variables seem to expand only within strings.
"query": {
"terms" : {
"container_id" : ctx.payload.first_query._value,
}
}
will give me errors like:
Unrecognized token 'ctx'
Would there be a way to insert an array without expanding to a string? If I use "ctx.payload.first_query._value" he will query for the string "[id1, id2]"...
Current workaround
I have currently implemented a workaround passing though a regex, but this seems a bit clunky:
"input": {
"chain": {
"inputs" : [ {
"container_ids" : {
...
}
}, {
"container_id_regex": {
"transform" : {
"script": """
def container_id_rexexp = "";
def regexp_separator = "";
for(def hit : ctx.payload.container_ids.hits.hits){
container_id_rexexp += regexp_separator + hit._source.container_id;
regexp_separator = "|";
}
return container_id_rexexp;
"""
}
}
}, {
"container_details": {
"search": {
"request": {
...
"body": {
"query": {
"regexp": {
"container_id": {
"value": "{{ '{{ctx.payload.container_id_regex._value}}' }}"
}
}
}
}
}
}
}
} ]
}
}