setup:
  - requires:
      cluster_features: ["gte_v8.11.0"]
      reason: "ESQL is available in 8.11+"
      test_runner_features: allowed_warnings_regex
  - do:
      indices.create:
        index: test
        body:
          settings:
            index:
              mode: standard
          mappings:
            properties:
              "@timestamp":
                type: date
              metricset:
                type: keyword
                time_series_dimension: true
              k8s:
                properties:
                  pod:
                    properties:
                      uid:
                        type: keyword
                        time_series_dimension: true
                      name:
                        type: keyword
                      ip:
                        type: ip
                      network:
                        properties:
                          tx:
                            type: long
                            time_series_metric: counter
                          rx:
                            type: long
                            time_series_metric: counter
  - do:
      bulk:
        refresh: true
        index: test
        body:
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2001818691, "rx": 802133794}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:24.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2005177954, "rx": 801479970}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:44.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.1", "network": {"tx": 2006223737, "rx": 802337279}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:51:04.467Z", "metricset": "pod", "k8s": {"pod": {"name": "cat", "uid":"947e4ced-1786-4e53-9e0c-5c447e959507", "ip": "10.10.55.2", "network": {"tx": 2012916202, "rx": 803685721}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434521831, "rx": 530575198}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:23.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434577921, "rx": 530600088}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:50:53.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434587694, "rx": 530604797}}}}'
          - '{"index": {}}'
          - '{"@timestamp": "2021-04-28T18:51:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}'

---
load everything:
  - do:
      allowed_warnings_regex:
        - "No limit defined, adding default limit of \\[.*\\]"
      esql.query:
        body:
          query: 'from test'

  - match: {columns.0.name: "@timestamp"}
  - match: {columns.0.type: "date"}
  - match: {columns.1.name: "k8s.pod.ip"}
  - match: {columns.1.type: "ip"}
  - match: {columns.2.name: "k8s.pod.name"}
  - match: {columns.2.type: "keyword"}
  - match: {columns.3.name: "k8s.pod.network.rx"}
  - match: {columns.3.type: "long"}
  - match: {columns.4.name: "k8s.pod.network.tx"}
  - match: {columns.4.type: "long"}
  - match: {columns.5.name: "k8s.pod.uid"}
  - match: {columns.5.type: "keyword"}
  - match: {columns.6.name: "metricset"}
  - match: {columns.6.type: "keyword"}
  - length: {values: 8}

---
load a document:
  - do:
      allowed_warnings_regex:
        - "No limit defined, adding default limit of \\[.*\\]"
      esql.query:
        body:
          query: 'from test | where @timestamp == "2021-04-28T18:50:23.142Z"'

  - length: {values: 1}
  - length: {values.0: 7}
  - match: {values.0.0: "2021-04-28T18:50:23.142Z"}
  - match: {values.0.1: "10.10.55.3"}
  - match: {values.0.2: "dog"}
  - match: {values.0.3: 530600088}
  - match: {values.0.4: 1434577921}
  - match: {values.0.5: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"}
  - match: {values.0.6: "pod"}

---
filter on counter:
  - do:
      allowed_warnings_regex:
        - "No limit defined, adding default limit of \\[.*\\]"
      esql.query:
        body:
          query: 'from test | where k8s.pod.network.tx == 1434577921'

  - length: {values: 1}
  - length: {values.0: 7}
  - match: {values.0.0: "2021-04-28T18:50:23.142Z"}
  - match: {values.0.1: "10.10.55.3"}
  - match: {values.0.2: "dog"}
  - match: {values.0.3: 530600088}
  - match: {values.0.4: 1434577921}
  - match: {values.0.5: "df3145b3-0563-4d3b-a0f7-897eb2876ea9"}
  - match: {values.0.6: "pod"}
