---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          properties:
            id:
              type: "integer"
            title:
              type: "text"
              term_vector: "with_positions_offsets"
            description:
              type: "text"
              term_vector: "with_positions_offsets"
            nested:
              type: "nested"
              properties:
                title:
                  type: "text"
                  term_vector: "with_positions_offsets"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "test"
      body:
        id: 1
        title: "The quick brown fox is brown"
        description: "The quick pink panther is pink"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    index:
      index: "test"
      body:
        id: 2
        title: "The quick blue fox is blue"
        nested:
        - title: "purple octopus"
        - title: "purple fish"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- do:
    indices.refresh:
      index:
      - "test"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
---
Highlight query:
- do:
    search:
      rest_total_hits_as_int: true
      body:
        query:
          term:
            id: "1"
        highlight:
          type: "fvh"
          fields:
            description:
              type: "fvh"
              highlight_query:
                prefix:
                  description: "br"
            title:
              type: "fvh"
              highlight_query:
                prefix:
                  title: "br"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0.highlight.title.0: "The quick <em>brown</em> fox is <em>brown</em>"
- is_false: "hits.hits.0.highlight.description"
---
Highlight multiple documents:
- requires:
    cluster_features:
    - "gte_v7.10.2"
    reason: "Bug fixed in 7.10.2"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        query:
          match:
            title: "fox"
        highlight:
          type: "fvh"
          fields:
            title:
              type: "fvh"
        sort:
        - "id"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0.highlight.title.0: "The quick brown <em>fox</em> is brown"
- is_false: "hits.hits.0.highlight.description"
- match:
    hits.hits.1.highlight.title.0: "The quick blue <em>fox</em> is blue"
- is_false: "hits.hits.1.highlight.description"
---
Highlight multiple nested documents:
- requires:
    cluster_features:
    - "gte_v7.10.2"
    reason: "Bug fixed in 7.10.2"
- do:
    search:
      rest_total_hits_as_int: true
      body:
        query:
          nested:
            path: "nested"
            query:
              match:
                nested.title: "purple"
            inner_hits:
              name: "nested_hits"
              highlight:
                type: "fvh"
                fields:
                  nested.title:
                    type: "fvh"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - "Use of the \\[max_size\\] rollover condition has been deprecated in favour\
      \ of the \\[max_primary_shard_size\\] condition and will be removed in a later\
      \ version"
    - "Parameter \\[confidence_interval\\] in \\[index_options\\] for dense_vector\
      \ field \\[[^\\]]+\\] is deprecated and will be removed in a future version"
- match:
    hits.hits.0.inner_hits.nested_hits.hits.hits.0.highlight.nested\.title.0: "<em>purple</em>\
      \ octopus"
- match:
    hits.hits.0.inner_hits.nested_hits.hits.hits.1.highlight.nested\.title.0: "<em>purple</em>\
      \ fish"
