---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
missing routing path field:
- requires:
    test_runner_features: "close_to"
    cluster_features:
    - "gte_v8.13.0"
    reason: "_tsid hashing introduced in 8.13"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "uid"
            - "tag"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            uid:
              type: "keyword"
              time_series_dimension: true
            voltage:
              type: "double"
              time_series_metric: "gauge"
            tag:
              type: "keyword"
              time_series_dimension: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      refresh: true
      index: "test"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:24.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.2, \"unmapped_field\": 10, \"tag\": \"first\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:34.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.0, \"unmapped_field\": 20 }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:44.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.4, \"unmapped_field\": 30, \"tag\": \"first\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:54.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.3, \"unmapped_field\": 40 }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:24.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.6, \"unmapped_field\": 10 }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:34.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.7, \"unmapped_field\": 20, \"tag\": \"second\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:44.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.7, \"unmapped_field\": 30, \"tag\": \"second\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:54.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.8, \"unmapped_field\": 40 }"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    search:
      index: "test"
      body:
        size: 0
        aggs:
          tsids:
            terms:
              field: "_tsid"
              order:
                _key: "asc"
            aggs:
              voltage:
                avg:
                  field: "voltage"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total.value: 8
- length:
    aggregations.tsids.buckets: 4
- match:
    aggregations.tsids.buckets.0.key: "JNy0BQX41tKNa3KEdjReXM85ihHDIG1DaFBdVI_fYOQvJgKOvg"
- match:
    aggregations.tsids.buckets.0.doc_count: 2
- close_to:
    aggregations.tsids.buckets.0.voltage.value:
      value: 6.69
      error: 0.01
- match:
    aggregations.tsids.buckets.1.key: "JNy0BQX41tKNa3KEdjReXM912oDh9NI69d0Kk5TQ6CAdewYP5A"
- match:
    aggregations.tsids.buckets.1.doc_count: 2
- close_to:
    aggregations.tsids.buckets.1.voltage.value:
      value: 7.15
      error: 0.01
- match:
    aggregations.tsids.buckets.2.key: "KDODRmbj7vu4rLWvjrJbpUuaET_vOYoRw6ImzKEcF4sEaGKnXSaKfM0"
- match:
    aggregations.tsids.buckets.2.doc_count: 2
- close_to:
    aggregations.tsids.buckets.2.voltage.value:
      value: 6.7
      error: 0.01
- match:
    aggregations.tsids.buckets.3.key: "KDODRmbj7vu4rLWvjrJbpUvcUWJEddqA4Seo8jbBBBFxwC0lrefCb6A"
- match:
    aggregations.tsids.buckets.3.doc_count: 2
- close_to:
    aggregations.tsids.buckets.3.voltage.value:
      value: 7.3
      error: 0.01
---
missing dimension on routing path field:
- requires:
    cluster_features:
    - "gte_v8.14.0"
    reason: "error message changed in 8.14.0"
- do:
    catch: "/All fields that match routing_path must be configured with \\[time_series_dimension:\
      \ true\\] or flattened fields with a list of dimensions in \\[time_series_dimensions\\\
      ] and without the \\[script\\] parameter. \\[tag\\] was not a dimension./"
    indices.create:
      index: "test"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "uid"
            - "tag"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            uid:
              type: "keyword"
              time_series_dimension: true
            voltage:
              type: "double"
              time_series_metric: "gauge"
            tag:
              type: "keyword"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
multi-value routing path field succeeds:
- requires:
    test_runner_features: "close_to"
    cluster_features:
    - "routing.multi_value_routing_path"
    reason: "support for multi-value dimensions"
- do:
    indices.create:
      index: "test"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "uid"
            - "tag"
            time_series:
              start_time: "2021-04-28T00:00:00Z"
              end_time: "2021-04-29T00:00:00Z"
        mappings:
          properties:
            '@timestamp':
              type: "date"
            uid:
              type: "keyword"
              time_series_dimension: true
            voltage:
              type: "double"
              time_series_metric: "gauge"
            tag:
              type: "keyword"
              time_series_dimension: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    bulk:
      refresh: true
      index: "test"
      body:
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:24.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.2, \"unmapped_field\": 10, \"tag\": \"first\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:34.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.0, \"unmapped_field\": 20, \"tag\": [ \"one\", \"two\" ]\
        \ }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:44.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.4, \"unmapped_field\": 30, \"tag\": \"first\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:54.467Z\", \"uid\": \"947e4ced-1786-4e53-9e0c-5c447e959507\"\
        , \"voltage\": 7.3, \"unmapped_field\": 40, \"tag\": [ \"one\", \"two\" ]\
        \ }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:24.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.6, \"unmapped_field\": 10, \"tag\": [ \"one\", \"three\"\
        \ ] }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:34.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.7, \"unmapped_field\": 20, \"tag\": \"second\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:44.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.7, \"unmapped_field\": 30, \"tag\": \"second\" }"
      - "{\"index\": {}}"
      - "{\"@timestamp\": \"2021-04-28T18:35:54.467Z\", \"uid\": \"df3145b3-0563-4d3b-a0f7-897eb2876ea9\"\
        , \"voltage\": 6.8, \"unmapped_field\": 40, \"tag\": [ \"one\", \"three\"\
        \ ] }"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- is_false: "errors"
- do:
    search:
      index: "test"
      body:
        size: 0
        aggs:
          tsids:
            terms:
              field: "_tsid"
              order:
                _key: "asc"
            aggs:
              voltage:
                avg:
                  field: "voltage"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.total.value: 8
- length:
    aggregations.tsids.buckets: 4
- match:
    aggregations.tsids.buckets.0.key: "KDODRmbj7vu4rLWvjrJbpUtt0uPSOYoRw_LI4DD7DFEGEJ3NR3eQkMY"
- match:
    aggregations.tsids.buckets.0.doc_count: 2
- close_to:
    aggregations.tsids.buckets.0.voltage.value:
      value: 6.7
      error: 0.01
- match:
    aggregations.tsids.buckets.1.key: "KDODRmbj7vu4rLWvjrJbpUtt0uPSddqA4WYKglGPR_C0cJe8QGaiC2c"
- match:
    aggregations.tsids.buckets.1.doc_count: 2
- close_to:
    aggregations.tsids.buckets.1.voltage.value:
      value: 7.15
      error: 0.01
- match:
    aggregations.tsids.buckets.2.key: "KDODRmbj7vu4rLWvjrJbpUuaET_vOYoRw6ImzKEcF4sEaGKnXSaKfM0"
- match:
    aggregations.tsids.buckets.2.doc_count: 2
- close_to:
    aggregations.tsids.buckets.2.voltage.value:
      value: 6.7
      error: 0.01
- match:
    aggregations.tsids.buckets.3.key: "KDODRmbj7vu4rLWvjrJbpUvcUWJEddqA4Seo8jbBBBFxwC0lrefCb6A"
- match:
    aggregations.tsids.buckets.3.doc_count: 2
- close_to:
    aggregations.tsids.buckets.3.voltage.value:
      value: 7.3
      error: 0.01
