setup:
  - do:
      indices.create:
        index: test
        body:
          mappings:
            properties:
              value:
                type: keyword
  - do:
      bulk:
        index: test
        refresh: true
        body:
          - '{"index": {}}'
          - '{"value": "a"}'
          - '{"index": {}}'
          - '{"value": "b"}'

---
"basic":
  - do:
      search:
        size: 0
        body:
          aggs:
            my_agg:
              string_stats:
                field: value
  - match: { aggregations.my_agg.count: 2 }
  - match: { aggregations.my_agg.min_length: 1 }
  - match: { aggregations.my_agg.max_length: 1 }
  - match: { aggregations.my_agg.avg_length: 1.0 }
  - match: { aggregations.my_agg.entropy: 1.0 }

---
"show_distribution":
  - do:
      search:
        size: 0
        body:
          aggs:
            my_agg:
              string_stats:
                field: value
                show_distribution: true
  - match: { aggregations.my_agg.count: 2 }
  - match: { aggregations.my_agg.min_length: 1 }
  - match: { aggregations.my_agg.max_length: 1 }
  - match: { aggregations.my_agg.avg_length: 1.0 }
  - match: { aggregations.my_agg.entropy: 1.0 }
  - match: { aggregations.my_agg.distribution.a: 0.5 }
  - match: { aggregations.my_agg.distribution.b: 0.5 }
