"ngram search":
  - do:
      indices.create:
        index: test
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
            analysis:
              analyzer:
                my_analyzer:
                  tokenizer: standard
                  filter: [my_ngram]
              filter:
                my_ngram:
                  type: ngram
                  min: 2,
                  max: 2
          mappings:
            properties:
              text:
                type: text
                analyzer: my_analyzer

  - do:
      index:
        index: test
        id:    "1"
        body:  { "text": "foo bar baz" }
        refresh: true

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              text:
                query: foa
  - match: {hits.total: 1}

---
"testNGramCopyField":
  - do:
      indices.create:
        index: test
        body:
          settings:
            number_of_shards: 1
            number_of_replicas: 0
            max_ngram_diff: 9
            analysis:
              analyzer:
                my_ngram_analyzer:
                  tokenizer: my_ngram_tokenizer
              tokenizer:
                my_ngram_tokenizer:
                  type: ngram
                  min: 1,
                  max: 10
                  token_chars: []
          mappings:
            properties:
              origin:
                type: text
                copy_to: meta
              meta:
                type: text
                analyzer: my_ngram_analyzer

  - do:
      index:
        index: test
        id:    "1"
        body:  { "origin": "C.A1234.5678" }
        refresh: true

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              meta:
                query: 1234
  - match: {hits.total: 1}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              meta:
                query: 1234.56
  - match: {hits.total: 1}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              meta:
                query: A1234
  - match: {hits.total: 1}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            term:
              meta:
                value: a1234
  - match: {hits.total: 0}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              meta:
                query: A1234
                analyzer: my_ngram_analyzer
  - match: {hits.total: 1}

  - do:
      search:
        rest_total_hits_as_int: true
        body:
          query:
            match:
              meta:
                query: a1234
                analyzer: my_ngram_analyzer
  - match: {hits.total: 1}
