# Wildcard in ctx.payload fileds

**URL:** <https://discuss.elastic.co/t/wildcard-in-ctx-payload-fileds/118009>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [February 1, 2018, 11:48am UTC](https://discuss.elastic.co/t/wildcard-in-ctx-payload-fileds/118009 "2018-02-01T11:48:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bodi4](https://avatars.discourse-cdn.com/v4/letter/b/57b2e6/32.png) [@bodi4](https://discuss.elastic.co/u/bodi4)\
**Post date:** [February 1, 2018, 11:48am UTC](https://discuss.elastic.co/t/wildcard-in-ctx-payload-fileds/118009/1 "2018-02-01T11:48:34Z")

</div>

Hi there!

I am making a watch with 2 chain searches: [search1, search2]. They differ only in query body and return same fields so I'd like to put it in one watch.

The question is:  
_How to write multiple conditions, i.e if there is a hit for any search, fire an alarm?_  
wildcard seems not work, only if write a search name _search1_ condition works

```
"condition": {
    "compare": {
      "ctx.payload.*.hits.total": {
        "gt": "0"
      }
    }
  }

```

If use script with **&&** to concatenate comparisons there is still a problem in Action section,  
How to access payload fields {{#ctx.payload.hits.hits}}{{key}}{{/ctx.payload.hits.hits}} for specific (triggered) condition/search?  
Or the only way to write 2 similar watches each with it own search?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 7, 2018, 8:50am UTC](https://discuss.elastic.co/t/wildcard-in-ctx-payload-fileds/118009/2 "2018-02-07T08:50:40Z")

</div>

Hey,

The compare condition cannot do this, you need to use scripting, i.e. like this (untested on top of my head)

```auto
"condition" :{
  "script" : "return ctx.payload.first.hits.total > 0 && ctx.payload.second.hits.total > 0"
}

```

Hope this helps!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 7, 2018, 8:50am UTC](https://discuss.elastic.co/t/wildcard-in-ctx-payload-fileds/118009/3 "2018-03-07T08:50:48Z")

</div>

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