Watcher using metadata array in input terms

Hello guys, I would like to know if it's possible to use metadata as an array like this:

"metadata": {
    "MyList": [
        "1",
        "2",
        "3",
        "4"
      ],
   "from": "60m"
 }

and use it as a parameters for my input:

 "input": {
     "search": {
       "request": {
         "search_type": "query_then_fetch",
         "indices": [
           "*test*"
         ],
         "rest_total_hits_as_int": true,
         "body": {
           "size": 0,
           "query": {
             "bool": {
               "must": [
                 {
                   "range": {
                     "@timestamp": {
                       "from": "now-{{ctx.metadata.from}}",
                       "to": "now"
                     }
                   }
                 },
                 {
                   "terms": {
                     **"id": "{{ctx.metadata.MyList}}"**
                   }
                 }
               ]
             }
           },
           "aggs": {
             "entite": {
               "terms": {
                 "field": "id.keyword"
               }
             }
           }
         }
       }
     }
   }

I would like that to act the same as:

{
"terms": {
    "id": [
        "1",
        "2",
        "3",
        "4"
   ],
}

But when i'm trying it, my terms is transformed to:

"terms": {
   "id": "{0=1, 1=2, 2=3, 3=4}"
 }

Do you have any idea, if it's possible? I would like to avoid to duplicate MyList inside a condition and inside the input.
Thanks in advance

up! :sob:

The ids query requires you to create an array, which is not possible using mustache templating.

How about using another query like this:

GET test/_search
{
  "query": {
    "query_string": {
      "default_field": "_id",
      "query": "1 OR 2 OR 3"
    }
  }
}

this way, you could use the join function

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.