---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "latency"
      body:
        mappings:
          properties:
            load_time:
              type: "double"
    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: "latency"
      - load_time: 2
      - index:
          _index: "latency"
      - load_time: 3
      - index:
          _index: "latency"
      - load_time: 5
      - index:
          _index: "latency"
      - load_time: 10
      - index:
          _index: "latency"
      - load_time: 15
      - index:
          _index: "latency"
      - {}
    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:
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
    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.plot.min: 2.0
- match:
    aggregations.plot.max: 15.0
- match:
    aggregations.plot.q1: 3.0
- match:
    aggregations.plot.q2: 5.0
- match:
    aggregations.plot.q3: 10.0
---
Search With Compression:
- do:
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              compression: 200
    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.plot.min: 2.0
- match:
    aggregations.plot.max: 15.0
- match:
    aggregations.plot.q1: 3.0
- match:
    aggregations.plot.q2: 5.0
- match:
    aggregations.plot.q3: 10.0
- do:
    catch: "/\\[compression\\] must be greater than or equal to 0. Found \\[-1.0\\\
      ] in \\[plot\\]/"
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              compression: -1.0
    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 With Execution Hint:
- do:
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              execution_hint: "high_accuracy"
    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.plot.min: 2.0
- match:
    aggregations.plot.max: 15.0
- match:
    aggregations.plot.q1: 2.75
- match:
    aggregations.plot.q2: 5.0
- match:
    aggregations.plot.q3: 11.25
- do:
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              execution_hint: "default"
    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.plot.min: 2.0
- match:
    aggregations.plot.max: 15.0
- match:
    aggregations.plot.q1: 3.0
- match:
    aggregations.plot.q2: 5.0
- match:
    aggregations.plot.q3: 10.0
- do:
    catch: "/Invalid execution_hint \\[no_such_hint\\], valid values are \\[default,\
      \ high_accuracy\\]/"
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              execution_hint: "no_such_hint"
    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 With Runtime Field:
- do:
    search:
      index: "latency"
      body:
        query:
          exists:
            field: "load_time"
        runtime_mappings:
          load_time_adjusted:
            type: "long"
            script:
              source: "emit((long)((doc['load_time'].value == 10 ? 1000 : doc['load_time'].value)\
                \ * params.multiplier))"
              params:
                multiplier: 10
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time_adjusted"
    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.plot.min: 20.0
- match:
    aggregations.plot.max: 10000.0
- match:
    aggregations.plot.q1: 30.0
- match:
    aggregations.plot.q2: 50.0
- match:
    aggregations.plot.q3: 150.0
- match:
    aggregations.plot.lower: 20.0
- match:
    aggregations.plot.upper: 150.0
---
Search With Missing:
- do:
    search:
      index: "latency"
      body:
        size: 0
        aggs:
          plot:
            boxplot:
              field: "load_time"
              missing: 10000
    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.plot.min: 2.0
- match:
    aggregations.plot.max: 10000.0
- match:
    aggregations.plot.q1: 3.5
- match:
    aggregations.plot.q2: 7.5
- match:
    aggregations.plot.q3: 13.75
- match:
    aggregations.plot.lower: 2.0
- match:
    aggregations.plot.upper: 15.0
---
Counter field:
- 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"
    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:
      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:
    - ".*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:
    search:
      index: "test_counter"
      body:
        aggs:
          counter_boxplot:
            boxplot:
              field: "counter"
    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:
    hits.total.value: 4
- length:
    hits.hits: 4
- close_to:
    aggregations.counter_boxplot.min:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_boxplot.max:
      value: 28.0
      error: 0.01
- close_to:
    aggregations.counter_boxplot.q1:
      value: 17.5
      error: 0.01
- close_to:
    aggregations.counter_boxplot.q2:
      value: 21.0
      error: 0.01
- close_to:
    aggregations.counter_boxplot.q3:
      value: 23.5
      error: 0.01
- close_to:
    aggregations.counter_boxplot.lower:
      value: 10.0
      error: 0.01
- close_to:
    aggregations.counter_boxplot.upper:
      value: 28.0
      error: 0.01
