---
"Basic array_compare watch":

  - do:
      cluster.health:
          wait_for_status: yellow

  - do:
      index:
          index:  test_1
          id:     "1"
          body:   { level: 0 }

  - do:
      index:
          index:  test_1
          id:     "2"
          body:   { level: 0 }

  - do:
      index:
          index:  test_1
          id:     "3"
          body:   { level: 0 }

  - do:
      index:
          index:  test_1
          id:     "4"
          body:   { level: 1 }
  - do:
      indices.refresh: {}

  - do:
      watcher.execute_watch:
        body:  >
          {
            "watch" : {
              "trigger": {
                "schedule": {
                  "interval": "5m"
                }
              },
              "input": {
                "search": {
                  "request": {
                    "indices": [ "test_1" ],
                    "rest_total_hits_as_int": true,
                    "body": {
                      "aggs": {
                        "top_levels": {
                          "terms": {
                            "field": "level",
                            "size": 1
                          }
                        }
                      }
                    }
                  }
                }
              },
              "condition": {
                "array_compare": {
                  "ctx.payload.aggregations.top_levels.buckets": {
                    "path": "doc_count",
                    "gte": {
                      "value": 3,
                      "quantifier": "some"
                    }
                  }
                }
              },
              "actions": {
                "log": {
                  "logging": {
                    "text": "executed at {{ctx.execution_time}}"
                  }
                }
              }
            }
          }


  - match: { "watch_record.result.input.status": "success" }
  - match: { "watch_record.result.input.payload.hits.total": 4 }
  - match: { "watch_record.result.condition.status": "success" }
  - match: { "watch_record.result.condition.met": true }
