---
setup:
  - do:
      indices.create:
          index: test1
          body:
              settings:
                  number_of_shards: 5
                  number_of_replicas: 1

  - do:
      indices.create:
          index: test2
          body:
              settings:
                  number_of_shards: 4
                  number_of_replicas: 1
  - do:
      index:
          index: test1
          type:  bar
          id:    1
          body:  { "foo": "bar" }

  - do:
      index:
          index: test2
          type:  baz
          id:    1
          body:  { "foo": "baz" }

---
"Index - blank":
  - do:
      indices.stats: {}

  - match: { _shards.total: 18 }
  - is_true: _all
  - is_true: indices.test1
  - is_true: indices.test2

---
"Index - all":
  - do:
      indices.stats: { index: _all }

  - match: { _shards.total: 18 }
  - is_true: _all
  - is_true: indices.test1
  - is_true: indices.test2


---
"Index - star":
  - do:
      indices.stats: { index: '*' }

  - match: { _shards.total: 18 }
  - is_true: _all
  - is_true: indices.test1
  - is_true: indices.test2

---
"Index - star, no match":
  - do:
      indices.stats: { index: 'bla*' }

  - match: { _shards.total: 0 }
  - is_true: _all
  - is_false: indices.test1
  - is_false: indices.test2

---
"Index - one index":
  - do:
      indices.stats: { index: 'test1' }

  - match: { _shards.total: 10 }
  - is_true: _all
  - is_true: indices.test1
  - is_false: indices.test2

---
"Index - multi-index":
  - do:
      indices.stats: { index: [test1, test2] }

  - match: { _shards.total: 18 }
  - is_true: _all
  - is_true: indices.test1
  - is_true: indices.test2

---
"Index - pattern":
  - do:
      indices.stats: { index: '*2' }

  - match: { _shards.total: 8 }
  - is_true: _all
  - is_false: indices.test1
  - is_true: indices.test2

---
"Indices stats unrecognized parameter":
  - skip:
      version: " - 5.0.99"
      reason: strict stats handling does not exist in 5.0
  - do:
      catch: bad_request
      indices.stats:
        metric: [ fieldata ]

  - match: { status: 400 }
  - match: { error.type: illegal_argument_exception }
  - match: { error.reason: "request [/_stats/fieldata] contains unrecognized metric: [fieldata] -> did you mean [fielddata]?" }
