---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "foo"
      body:
        mappings:
          properties:
            timestamp:
              type: "date"
            partition:
              type: "keyword"
            price:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "dummy-rollup-index"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
        mappings:
          _meta:
            _rollup:
              my-id: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1h\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "foo"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "foo"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "b"
        partition.terms._count: 10
        price.max.value: 4
        _rollup.id: "foo"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Basic Search:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
---
Basic Search with rest_total_hits_as_int:
- requires:
    cluster_features:
    - "gte_v6.6.0"
    reason: "rest_total_hits_as_int was introduced in 6.6.0"
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
---
Formatted Date Histo:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
              format: "yyyy-MM-dd"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01"
- match:
    aggregations.histo.buckets.3.doc_count: 20
---
Empty aggregation:
- do:
    rollup.rollup_search:
      rest_total_hits_as_int: true
      index: "foo_rollup"
      body:
        size: 0
        aggs: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    hits.hits: 0
- match:
    hits.total: 0
- is_false: "aggregations"
---
Empty aggregation with new response format:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    hits.hits: 0
- match:
    hits.total.value: 0
- match:
    hits.total.relation: "eq"
- is_false: "aggregations"
---
Search with Metric:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
- match:
    aggregations.histo.buckets.3.the_max.value: 4
---
Search with Query:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        query:
          term:
            partition: "a"
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 0
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 10
- match:
    aggregations.histo.buckets.3.the_max.value: 3
---
Search with MatchAll and Second Job:
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo2"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1h\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "b"
        partition.terms._count: 10
        price.max.value: 4
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
- match:
    aggregations.histo.buckets.3.the_max.value: 4
---
Search with Query and Second Job:
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo2"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1h\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "b"
        partition.terms._count: 10
        price.max.value: 4
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        query:
          term:
            partition: "a"
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 0
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 10
- match:
    aggregations.histo.buckets.3.the_max.value: 3
---
Search with Query and Second Job different intervals:
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "foo2"
      body: "{\n  \"index_pattern\": \"foo\",\n  \"rollup_index\": \"foo_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1d\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T05:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T06:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T07:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "b"
        partition.terms._count: 10
        price.max.value: 4
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
      - index:
          _index: "foo_rollup"
      - timestamp.date_histogram.timestamp: "2017-01-01T08:00:00Z"
        timestamp.date_histogram.interval: "1h"
        timestamp.date_histogram.time_zone: "UTC"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "foo2"
        _rollup.computed:
        - "timestamp.date_histogram"
        - "partition.terms"
        _rollup.version: 1
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      body:
        size: 0
        query:
          term:
            partition: "a"
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 0
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 10
- match:
    aggregations.histo.buckets.3.the_max.value: 3
---
Wildcards matching single rollup index:
- do:
    rollup.rollup_search:
      index: "foo_rollup*"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
---
Wildcards matching two rollup indices:
- do:
    indices.create:
      index: "bar"
      body:
        mappings:
          properties:
            timestamp:
              type: "date"
            partition:
              type: "keyword"
            price:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "bar"
      body: "{\n  \"index_pattern\": \"bar\",\n  \"rollup_index\": \"bar_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1h\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/RollupSearch currently only supports searching one rollup index at a\
      \ time\\./"
    rollup.rollup_search:
      index: "*_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Rollup search via alias:
- do:
    indices.put_alias:
      index: "foo_rollup"
      name: "rollup_alias"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "rollup_alias"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 4
- match:
    aggregations.histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.histo.buckets.3.doc_count: 20
---
Rollup search via alias, multiple rollup indices match:
- do:
    indices.create:
      index: "bar"
      body:
        mappings:
          properties:
            timestamp:
              type: "date"
            partition:
              type: "keyword"
            price:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    rollup.put_job:
      id: "bar"
      body: "{\n  \"index_pattern\": \"bar\",\n  \"rollup_index\": \"bar_rollup\"\
        ,\n  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"calendar_interval\"\
        : \"1h\"\n    },\n    \"terms\": {\n      \"fields\": [\"partition\"]\n  \
        \  }\n  },\n  \"metrics\": [\n    {\n      \"field\": \"price\",\n      \"\
        metrics\": [\"max\"]\n    }\n  ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.put_alias:
      index: "foo_rollup,bar_rollup"
      name: "rollup_alias"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    catch: "/RollupSearch currently only supports searching one rollup index at a\
      \ time\\./"
    rollup.rollup_search:
      index: "rollup_alias"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Obsolete Timezone:
- requires:
    cluster_features:
    - "gte_v7.2.0"
    reason: "IANA TZ deprecations in 7.2"
    test_runner_features: "warnings"
- do:
    indices.create:
      index: "tz"
      body:
        mappings:
          properties:
            timestamp:
              type: "date"
            partition:
              type: "keyword"
            price:
              type: "integer"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    warnings:
    - "Creating Rollup job [tz] with timezone [Canada/Mountain], but [Canada/Mountain]\
      \ has been deprecated by the IANA.  Use [America/Edmonton] instead."
    rollup.put_job:
      id: "tz"
      body: "{\n  \"index_pattern\": \"tz\",\n  \"rollup_index\": \"tz_rollup\",\n\
        \  \"cron\": \"*/30 * * * * ?\",\n  \"page_size\" :10,\n  \"groups\" : {\n\
        \    \"date_histogram\": {\n      \"field\": \"timestamp\",\n      \"fixed_interval\"\
        : \"5m\",\n      \"time_zone\": \"Canada/Mountain\"\n    },\n    \"terms\"\
        : {\n      \"fields\": [\"partition\"]\n    }\n  },\n  \"metrics\": [\n  \
        \  {\n      \"field\": \"price\",\n      \"metrics\": [\"max\"]\n    }\n \
        \ ]\n}\n"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221000000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "America/Edmonton"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "tz"
        _rollup.version: 2
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221300000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "America/Edmonton"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "tz"
        _rollup.version: 2
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221600000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "America/Edmonton"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "tz"
        _rollup.version: 2
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "tz_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "5m"
              time_zone: "America/Edmonton"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 3
- match:
    aggregations.histo.buckets.0.key_as_string: "2018-07-10T05:10:00.000-06:00"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2018-07-10T05:15:00.000-06:00"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2018-07-10T05:20:00.000-06:00"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- do:
    rollup.rollup_search:
      index: "tz_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "5m"
              time_zone: "Canada/Mountain"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 3
- match:
    aggregations.histo.buckets.0.key_as_string: "2018-07-10T05:10:00.000-06:00"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2018-07-10T05:15:00.000-06:00"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2018-07-10T05:20:00.000-06:00"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
---
Obsolete BWC Timezone:
- requires:
    cluster_features:
    - "gte_v7.2.0"
    reason: "IANA TZ deprecations in 7.2"
- do:
    indices.create:
      index: "tz_rollup"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
        mappings:
          properties:
            partition.terms.value:
              type: "keyword"
            partition.terms._count:
              type: "long"
            timestamp.date_histogram.time_zone:
              type: "keyword"
            timestamp.date_histogram.interval:
              type: "keyword"
            timestamp.date_histogram.timestamp:
              type: "date"
            timestamp.date_histogram._count:
              type: "long"
            price.max.value:
              type: "double"
            _rollup.id:
              type: "keyword"
            _rollup.version:
              type: "long"
          _meta:
            _rollup:
              sensor:
                cron: "* * * * * ?"
                rollup_index: "tz_rollup"
                index_pattern: "tz"
                timeout: "20s"
                page_size: 1000
                groups:
                  date_histogram:
                    field: "timestamp"
                    interval: "5m"
                    time_zone: "Canada/Mountain"
                  terms:
                    fields:
                    - "partition"
                id: "tz"
                metrics:
                - field: "price"
                  metrics:
                  - "max"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    bulk:
      refresh: true
      body:
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221000000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "Canada/Mountain"
        timestamp.date_histogram._count: 1
        partition.terms.value: "a"
        partition.terms._count: 1
        price.max.value: 1
        _rollup.id: "tz"
        _rollup.version: 2
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221300000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "Canada/Mountain"
        timestamp.date_histogram._count: 2
        partition.terms.value: "b"
        partition.terms._count: 2
        price.max.value: 2
        _rollup.id: "tz"
        _rollup.version: 2
      - index:
          _index: "tz_rollup"
      - timestamp.date_histogram.timestamp: 1531221600000
        timestamp.date_histogram.interval: "5m"
        timestamp.date_histogram.time_zone: "Canada/Mountain"
        timestamp.date_histogram._count: 10
        partition.terms.value: "a"
        partition.terms._count: 10
        price.max.value: 3
        _rollup.id: "tz"
        _rollup.version: 2
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    rollup.rollup_search:
      index: "tz_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "5m"
              time_zone: "America/Edmonton"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 3
- match:
    aggregations.histo.buckets.0.key_as_string: "2018-07-10T05:10:00.000-06:00"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2018-07-10T05:15:00.000-06:00"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2018-07-10T05:20:00.000-06:00"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
- do:
    rollup.rollup_search:
      index: "tz_rollup"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "5m"
              time_zone: "Canada/Mountain"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- length:
    aggregations.histo.buckets: 3
- match:
    aggregations.histo.buckets.0.key_as_string: "2018-07-10T05:10:00.000-06:00"
- match:
    aggregations.histo.buckets.0.doc_count: 1
- match:
    aggregations.histo.buckets.0.the_max.value: 1
- match:
    aggregations.histo.buckets.1.key_as_string: "2018-07-10T05:15:00.000-06:00"
- match:
    aggregations.histo.buckets.1.doc_count: 2
- match:
    aggregations.histo.buckets.1.the_max.value: 2
- match:
    aggregations.histo.buckets.2.key_as_string: "2018-07-10T05:20:00.000-06:00"
- match:
    aggregations.histo.buckets.2.doc_count: 10
- match:
    aggregations.histo.buckets.2.the_max.value: 3
---
Search with typed_keys:
- do:
    rollup.rollup_search:
      index: "foo_rollup"
      typed_keys: true
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              calendar_interval: "1h"
              time_zone: "UTC"
            aggs:
              the_max:
                max:
                  field: "price"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    aggregations.date_histogram#histo.buckets.0.key_as_string: "2017-01-01T05:00:00.000Z"
- match:
    aggregations.date_histogram#histo.buckets.0.doc_count: 1
- match:
    aggregations.date_histogram#histo.buckets.0.max#the_max.value: 1
- match:
    aggregations.date_histogram#histo.buckets.1.key_as_string: "2017-01-01T06:00:00.000Z"
- match:
    aggregations.date_histogram#histo.buckets.1.doc_count: 2
- match:
    aggregations.date_histogram#histo.buckets.1.max#the_max.value: 2
- match:
    aggregations.date_histogram#histo.buckets.2.key_as_string: "2017-01-01T07:00:00.000Z"
- match:
    aggregations.date_histogram#histo.buckets.2.doc_count: 10
- match:
    aggregations.date_histogram#histo.buckets.2.max#the_max.value: 3
- match:
    aggregations.date_histogram#histo.buckets.3.key_as_string: "2017-01-01T08:00:00.000Z"
- match:
    aggregations.date_histogram#histo.buckets.3.doc_count: 20
- match:
    aggregations.date_histogram#histo.buckets.3.max#the_max.value: 4
---
Search error against live index:
- do:
    catch: "bad_request"
    rollup.rollup_search:
      index: "foo"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "asdfasdf"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Search error against rollup and live index:
- do:
    catch: "bad_request"
    rollup.rollup_search:
      index: "foo*"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "asdfasdf"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Search error no matching indices:
- do:
    catch: "/Must specify at least one concrete index/"
    rollup.rollup_search:
      index: "bar*"
      body:
        size: 0
        aggs:
          histo:
            date_histogram:
              field: "timestamp"
              fixed_interval: "1h"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
