---
setup:
  - requires:
      cluster_features: ["mapper.keyword.high_cardinality_length_function_fuse_to_load"]
      reason: "testing binary doc values search"

  - do:
      indices.create:
        index:  test
        body:
          mappings:
            dynamic: false
            properties:
              keyword:
                type: keyword
                index: false
                doc_values:
                  cardinality: high

  - do:
      index:
        index: test
        id: "1"
        body:
          keyword: "abc"

  - do:
      index:
        index: test
        id: "2"
        body:
          keyword: "abcdef"
  - do:
      indices.refresh: {}

---
"Test avg length":
  - do:
      esql.query:
        body:
          query: 'FROM test | STATS l = avg(length(keyword)) | LIMIT 10'

  - length: {columns: 1}
  - length: {values: 1}
  - match: {columns.0.name: "l"}
  - match: {columns.0.type: "double"}
  - length: {values.0: 1}
  - match: {values.0.0: 4.5}
