---
setup:
  - do:
      indices.create:
          index: test1
          body:
              settings:
                  number_of_shards: 1
                  index.highlight.max_analyzed_offset: 10
              mappings:
                  test_type:
                      properties:
                          field1:
                              type: text
                          field2:
                              type: text
                              index_options: offsets

  - do:
      index:
          index: test1
          type:  test_type
          id:    1
          body:
              "field1" : "The quick brown fox went to the forest and saw another fox."
              "field2" : "The quick brown fox went to the forest and saw another fox."

  - do:
      indices.refresh: {}

---
"Unified highlighter on a field WITHOUT OFFSETS exceeding index.highlight.max_analyzed_offset should FAIL":
  - skip:
      version: " - 6.99.99"
      reason: index.highlight.max_analyzed_offset setting has been added in 7.0.0
  - do:
      catch: bad_request
      search:
          index: test1
          body: {"query" : {"match" : {"field1" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field1" : {}}}}
  - match: { error.root_cause.0.type: "illegal_argument_exception" }


---
"Plain highlighter on a field WITHOUT OFFSETS exceeding index.highlight.max_analyzed_offset should FAIL":
  - skip:
      version: " - 6.99.99"
      reason: index.highlight.max_analyzed_offset setting has been added in 7.0.0
  - do:
      catch: bad_request
      search:
          index: test1
          body: {"query" : {"match" : {"field1" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field1" : {}}}}
  - match: { error.root_cause.0.type: "illegal_argument_exception" }


---
"Unified highlighter on a field WITH OFFSETS exceeding index.highlight.max_analyzed_offset should SUCCEED":
  - skip:
      version: " - 6.99.99"
      reason: index.highligt.max_analyzed_offset setting has been added in 7.0.0
  - do:
      search:
          index: test1
          body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "unified", "fields" : {"field2" : {}}}}
  - match: {hits.hits.0.highlight.field2.0: "The quick brown <em>fox</em> went to the forest and saw another <em>fox</em>."}


---
"Plain highlighter on a field WITH OFFSETS exceeding index.highlight.max_analyzed_offset should FAIL":
  - skip:
      version: " - 6.99.99"
      reason: index.highlight.max_analyzed_offset setting has been added in 7.0.0
  - do:
      catch: bad_request
      search:
          index: test1
          body: {"query" : {"match" : {"field2" : "fox"}}, "highlight" : {"type" : "plain", "fields" : {"field2" : {}}}}
  - match: { error.root_cause.0.type: "illegal_argument_exception" }
