---
"Analyze API setup":
    - do:
        indices.create:
          index: test
          body:
              mappings:
                test:
                  properties:
                    text:
                      type:     string
                      analyzer: whitespace

---
"Analyze API text format":
    - do:
        indices.analyze:
          format: text
          text: tHE BLACK and white! AND red
    - match:
        tokens: "[black:4->9:<ALPHANUM>]\n\n4: \n[white:14->19:<ALPHANUM>]\n\n6: \n[red:25->28:<ALPHANUM>]\n"

---
"Analyze API JSON format":
    - do:
        indices.analyze:
          text: Foo Bar
    - length: { tokens: 2 }
    - match:     { tokens.0.token: foo }
    - match:     { tokens.1.token: bar }

---
"Analyze API JSON format - tokenizer and filter":
    - do:
        indices.analyze:
          filters:      lowercase
          text:         Foo Bar
          tokenizer:    keyword
    - length: { tokens: 1 }
    - match:     { tokens.0.token: foo bar }

---
"Analyze API JSON format - index and field":
    - do:
        indices.analyze:
          field: text
          index: test
          text: Foo Bar!
    - length: { tokens: 2 }
    - match:     { tokens.0.token: Foo }
    - match:     { tokens.1.token: Bar! }


---
"Analyze API setup":
    - do:
        indices.create:
          index: test
          body:
              mappings:
                test:
                  properties:
                    text:
                      type:     string
                      analyzer: whitespace

---
"Analyze API text format":
    - do:
        indices.analyze:
          format: text
          text: tHE BLACK and white! AND red
    - match:
        tokens: "[black:4->9:<ALPHANUM>]\n\n4: \n[white:14->19:<ALPHANUM>]\n\n6: \n[red:25->28:<ALPHANUM>]\n"

---
"Analyze API JSON format":
    - do:
        indices.analyze:
          text: Foo Bar
    - length: { tokens: 2 }
    - match:     { tokens.0.token: foo }
    - match:     { tokens.1.token: bar }

---
"Analyze API JSON format - tokenizer and filter":
    - do:
        indices.analyze:
          filters:      lowercase
          text:         Foo Bar
          tokenizer:    keyword
    - length: { tokens: 1 }
    - match:     { tokens.0.token: foo bar }

---
"Analyze API JSON format - index and field":
    - do:
        cluster.health:
          wait_for_status: yellow

    - do:
        indices.analyze:
          field: text
          index: test
          text: Foo Bar!
    - length: { tokens: 2 }
    - match:     { tokens.0.token: Foo }
    - match:     { tokens.1.token: Bar! }


Replace refresh with cluster.health check
Replace refresh with cluster.health check

Possible to fail this test with a 500 NoShardsAvailable error, due
to the index not being fully allocated before the analyze call is
executed.

Changing for a wait_for_status: yellow fixes the occasional problem.
