# Elastic watcher - modify query result value before condition

**URL:** <https://discuss.elastic.co/t/elastic-watcher-modify-query-result-value-before-condition/226908>\
**Category:** Elasticsearch\
**Created:** [April 7, 2020, 1:40pm UTC](https://discuss.elastic.co/t/elastic-watcher-modify-query-result-value-before-condition/226908 "2020-04-07T13:40:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![vdelcampo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vdelcampo/32/65731_2.png) [@vdelcampo](https://discuss.elastic.co/u/vdelcampo)\
**Post date:** [April 7, 2020, 1:40pm UTC](https://discuss.elastic.co/t/elastic-watcher-modify-query-result-value-before-condition/226908/1 "2020-04-07T13:40:04Z")

</div>

Hi.

Im trying to create a watcher to compare two query results. Here is my code (it works):

```
{
  "trigger": {
   "schedule": {
    "interval": "1m"
    }
 },
"input": {
  "chain": {
    "inputs": [
    {
      "first": {
        "search": {
          "request": {
            "search_type": "query_then_fetch",
            "indices": [
              "<my_index-{now/d}>"
            ],
            "rest_total_hits_as_int": true,
            "body": {
              "size": 0,
              "query": {
                "bool": {
                  "must": [
                            {
                      "range": {
                        "@timestamp": {
                          "gte": "now-2m",
                          "lt": "now-1m"
                        }
                      }
                    },
                    {
                      "match": {
                        "http_path": "my_path/mypath.aspx"
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    },
    {
      "second": {
        "search": {
          "request": {
            "search_type": "query_then_fetch",
            "indices": [
              "<my_index-{now/d}>"
            ],
            "rest_total_hits_as_int": true,
            "body": {
              "size": 0,
              "query": {
                "bool": {
                  "must": [
                    {
                      "range": {
                        "@timestamp": {
                          "gte": "now-1m",
                          "lt": "now"
                        }
                      }
                    },
                    {
                      "match": {
                        "http_path": "my_path/mypath.aspx"
                      }
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  ]
}
},
   "condition": {
      "compare": {
       "ctx.payload.first.hits.total": {
        "gt": "{{(ctx.payload.second.hits.total)}}"
  }
}
 },
"actions": {
     "log": {
     "logging": {
       "level": "info",
        "text": "First is greater than second"
  }
}
}
}

```

I need to calculate the 60% of ctx.payload.first.hits.total, then compare with ctx.payload.second.hits.total. How can i do that? I tried to do a transform, and also tried scripts with no success.

Thanks in advance!

Regards,

Víctor

---

<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:** [May 5, 2020, 1:40pm UTC](https://discuss.elastic.co/t/elastic-watcher-modify-query-result-value-before-condition/226908/2 "2020-05-05T13:40:13Z")

</div>

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