---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
'friendlier BUCKET interval hourly: #110916':
- requires:
    test_runner_features:
    - "allowed_warnings_regex"
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "bucket_inclusive_upper_bound"
    reason: "BUCKET auto mode now generates different bucket sizes"
- do:
    indices.create:
      index: "test_bucket"
      body:
        mappings:
          properties:
            ts:
              type: "date"
    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:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16T08:10:00Z"
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16T09:20:00Z"
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16T10:30:00Z"
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16T11:40:00Z"
    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:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | SORT ts"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "ts"
- match:
    columns.0.type: "date"
- length:
    values: 4
- match:
    values.0.0: "2024-07-16T08:10:00.000Z"
- match:
    values.1.0: "2024-07-16T09:20:00.000Z"
- match:
    values.2.0: "2024-07-16T10:30:00.000Z"
- match:
    values.3.0: "2024-07-16T11:40:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 4, \"2024-07-16T08:00:00Z\"\
          , \"2024-07-16T12:00:00Z\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 4
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-07-16T08:00:00.000Z"
- match:
    values.1.0: 1
- match:
    values.1.1: "2024-07-16T09:00:00.000Z"
- match:
    values.2.0: 1
- match:
    values.2.1: "2024-07-16T10:00:00.000Z"
- match:
    values.3.0: 1
- match:
    values.3.1: "2024-07-16T11:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 4, \"2024-07-16T08:00:00Z\"\
          , \"2024-07-16T12:00:00.001Z\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 2
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-07-16T06:00:00.000Z"
- match:
    values.1.0: 3
- match:
    values.1.1: "2024-07-16T09:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 4, \"2024-07-16T08:09:00Z\"\
          , \"2024-07-16T12:00:00Z\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 4
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-07-16T08:00:00.000Z"
- match:
    values.1.0: 1
- match:
    values.1.1: "2024-07-16T09:00:00.000Z"
- match:
    values.2.0: 1
- match:
    values.2.1: "2024-07-16T10:00:00.000Z"
- match:
    values.3.0: 1
- match:
    values.3.1: "2024-07-16T11:00:00.000Z"
---
'friendlier BUCKET interval: monthly #110916':
- requires:
    cluster_features:
    - "gte_v8.14.0"
    test_runner_features:
    - "allowed_warnings_regex"
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "bucket_inclusive_upper_bound"
    reason: "BUCKET auto mode now generates different bucket sizes"
- do:
    indices.create:
      index: "test_bucket"
      body:
        mappings:
          properties:
            ts:
              type: "date"
    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:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_bucket"
      - ts: "2024-06-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-08-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-09-16"
    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:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    values.0.0: 4
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | SORT ts"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "ts"
- match:
    columns.0.type: "date"
- length:
    values: 4
- match:
    values.0.0: "2024-06-16T00:00:00.000Z"
- match:
    values.1.0: "2024-07-16T00:00:00.000Z"
- match:
    values.2.0: "2024-08-16T00:00:00.000Z"
- match:
    values.3.0: "2024-09-16T00:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*)"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    values.0.0: 4
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 11, \"2024-01-01\"\
          , \"2025-01-01\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 1
- match:
    values.0.0: 4
- match:
    values.0.1: "2024-01-01T00:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 12, \"2024-01-01\"\
          , \"2025-01-01\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 4
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-06-01T00:00:00.000Z"
- match:
    values.1.0: 1
- match:
    values.1.1: "2024-07-01T00:00:00.000Z"
- match:
    values.2.0: 1
- match:
    values.2.1: "2024-08-01T00:00:00.000Z"
- match:
    values.3.0: 1
- match:
    values.3.1: "2024-09-01T00:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 12, \"2024-01-01\"\
          , \"2025-01-01T00:00:00.001\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 1
- match:
    values.0.0: 4
- match:
    values.0.1: "2024-01-01T00:00:00.000Z"
- do:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, 13, \"2024-01-01T12:13:14Z\"\
          , \"2025-01-01\") | SORT b"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 4
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-06-01T00:00:00.000Z"
- match:
    values.1.0: 1
- match:
    values.1.1: "2024-07-01T00:00:00.000Z"
- match:
    values.2.0: 1
- match:
    values.2.1: "2024-08-01T00:00:00.000Z"
- match:
    values.3.0: 1
- match:
    values.3.1: "2024-09-01T00:00:00.000Z"
---
Datetime interval as string:
- requires:
    test_runner_features:
    - "allowed_warnings_regex"
    - "capabilities"
    capabilities:
    - method: "POST"
      path: "/_query"
      parameters: []
      capabilities:
      - "implicit_casting_string_literal_to_temporal_amount"
    reason: "interval in parameters as string"
- do:
    indices.create:
      index: "test_bucket"
      body:
        mappings:
          properties:
            ts:
              type: "date"
    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:
    bulk:
      refresh: true
      body:
      - index:
          _index: "test_bucket"
      - ts: "2024-06-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-07-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-08-16"
      - index:
          _index: "test_bucket"
      - ts: "2024-09-16"
    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:
    allowed_warnings_regex:
    - "No limit defined, adding default limit of \\[.*\\]"
    - ".*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"
    esql.query:
      body:
        query: "FROM test_bucket | STATS c = COUNT(*) BY b = BUCKET(ts, ?bucket) |\
          \ SORT b"
        params:
        - bucket: "1 month"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
- match:
    columns.0.name: "c"
- match:
    columns.0.type: "long"
- match:
    columns.1.name: "b"
- match:
    columns.1.type: "date"
- length:
    values: 4
- match:
    values.0.0: 1
- match:
    values.0.1: "2024-06-01T00:00:00.000Z"
- match:
    values.1.0: 1
- match:
    values.1.1: "2024-07-01T00:00:00.000Z"
- match:
    values.2.0: 1
- match:
    values.2.1: "2024-08-01T00:00:00.000Z"
- match:
    values.3.0: 1
- match:
    values.3.1: "2024-09-01T00:00:00.000Z"
