---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- requires:
    cluster_features:
    - "gte_v8.10.0"
    reason: "counter field support added in 8.10"
    test_runner_features: "close_to"
- do:
    indices.create:
      index: "test_counter"
      body:
        settings:
          index:
            mode: "time_series"
            routing_path:
            - "key"
            time_series:
              start_time: "2021-01-01T00:00:00Z"
              end_time: "2021-01-31T00:00:00Z"
            number_of_shards: 1
        mappings:
          properties:
            '@timestamp':
              type: "date"
            key:
              type: "keyword"
              time_series_dimension: true
            counter:
              type: "long"
              time_series_metric: "counter"
            weight:
              type: "integer"
    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:
      index: "test_counter"
      refresh: true
      body:
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:01:00Z\", \"key\": \"bar\", \"counter\"\
        : 10, \"weight\": 2 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:02:00Z\", \"key\": \"bar\", \"counter\"\
        : 20, \"weight\": 1 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:03:00Z\", \"key\": \"bar\", \"counter\"\
        : 22, \"weight\": 2 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:04:00Z\", \"key\": \"bar\", \"counter\"\
        : 28, \"weight\": 1 }"
    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"
---
avg:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_avg:
            avg:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_avg.value:
      value: 20.0
      error: 0.01
---
cardinality:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_cardinality:
            cardinality:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- match:
    aggregations.counter_cardinality.value: 4
---
extended stats:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_extended_stats:
            extended_stats:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- match:
    aggregations.counter_extended_stats.count: 4
- close_to:
    aggregations.counter_extended_stats.min:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.max:
      value: 28.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.avg:
      value: 20.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.sum:
      value: 80.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.sum_of_squares:
      value: 1768.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.std_deviation:
      value: 6.48
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.std_deviation_bounds.upper:
      value: 32.96
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.std_deviation_bounds.lower:
      value: 7.03
      error: 0.01
---
median absolute deviation:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          mad_counter:
            median_absolute_deviation:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.mad_counter.value:
      value: 4.0
      error: 0.01
---
percentile ranks hdr:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_percentile_ranks:
            percentile_ranks:
              field: "counter"
              values:
              - 50
              - 90
              keyed: false
              hdr:
                number_of_significant_value_digits: 2
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_percentile_ranks.values.0.value:
      value: 100.0
      error: 0.01
- close_to:
    aggregations.counter_percentile_ranks.values.1.value:
      value: 100.0
      error: 0.01
---
percentile ranks tdigest:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_percentiles:
            percentiles:
              field: "counter"
              keyed: false
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_percentiles.values.0.value:
      value: 10.3
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.1.value:
      value: 11.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.2.value:
      value: 17.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.3.value:
      value: 21.0
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.4.value:
      value: 23.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.5.value:
      value: 27.1
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.6.value:
      value: 27.82
      error: 0.01
---
percentiles hdr:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_percentiles:
            percentiles:
              field: "counter"
              keyed: false
              hdr:
                number_of_significant_value_digits: 2
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_percentiles.values.0.value:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.1.value:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.2.value:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.3.value:
      value: 20.06
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.4.value:
      value: 22.06
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.5.value:
      value: 28.06
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.6.value:
      value: 28.06
      error: 0.01
---
percentiles tdigest:
- do:
    bulk:
      index: "test_counter"
      refresh: true
      body:
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:01:00Z\", \"key\": \"bar\", \"counter\"\
        : 10 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:02:00Z\", \"key\": \"bar\", \"counter\"\
        : 20 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:03:00Z\", \"key\": \"bar\", \"counter\"\
        : 22 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:04:00Z\", \"key\": \"bar\", \"counter\"\
        : 28 }"
    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_counter"
      body:
        aggs:
          counter_percentiles:
            percentiles:
              field: "counter"
              keyed: false
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_percentiles.values.0.value:
      value: 10.3
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.1.value:
      value: 11.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.2.value:
      value: 17.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.3.value:
      value: 21.0
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.4.value:
      value: 23.5
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.5.value:
      value: 27.1
      error: 0.01
- close_to:
    aggregations.counter_percentiles.values.6.value:
      value: 27.82
      error: 0.01
---
stats:
- do:
    bulk:
      index: "test_counter"
      refresh: true
      body:
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:01:00Z\", \"key\": \"bar\", \"counter\"\
        : 10 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:02:00Z\", \"key\": \"bar\", \"counter\"\
        : 20 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:03:00Z\", \"key\": \"bar\", \"counter\"\
        : 22 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:04:00Z\", \"key\": \"bar\", \"counter\"\
        : 28 }"
    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_counter"
      body:
        aggs:
          counter_extended_stats:
            stats:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- match:
    aggregations.counter_extended_stats.count: 4
- close_to:
    aggregations.counter_extended_stats.min:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.max:
      value: 28.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.avg:
      value: 20.0
      error: 0.01
- close_to:
    aggregations.counter_extended_stats.sum:
      value: 80.0
      error: 0.01
---
sum:
- do:
    bulk:
      index: "test_counter"
      refresh: true
      body:
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:01:00Z\", \"key\": \"bar\", \"counter\"\
        : 10 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:02:00Z\", \"key\": \"bar\", \"counter\"\
        : 20 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:03:00Z\", \"key\": \"bar\", \"counter\"\
        : 22 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:04:00Z\", \"key\": \"bar\", \"counter\"\
        : 28 }"
    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_counter"
      body:
        aggs:
          counter_sum:
            sum:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_sum.value:
      value: 80.0
      error: 0.01
---
value count:
- do:
    bulk:
      index: "test_counter"
      refresh: true
      body:
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:01:00Z\", \"key\": \"bar\", \"counter\"\
        : 10 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:02:00Z\", \"key\": \"bar\", \"counter\"\
        : 20 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:03:00Z\", \"key\": \"bar\", \"counter\"\
        : 22 }"
      - "{ \"index\": {} }"
      - "{ \"@timestamp\": \"2021-01-01T00:04:00Z\", \"key\": \"bar\", \"counter\"\
        : 28 }"
    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_counter"
      body:
        aggs:
          counter_value_count:
            value_count:
              field: "counter"
    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: 4
- length:
    hits.hits: 4
- match:
    aggregations.counter_value_count.value: 4
---
weighted avg:
- do:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_weighted_avg:
            weighted_avg:
              value:
                field: "counter"
              weight:
                field: "weight"
    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: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_weighted_avg.value:
      value: 18.66
      error: 0.01
