---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "test"
      body:
        mappings:
          _source:
            excludes:
            - "nested.stored_only"
          properties:
            nested:
              type: "nested"
              properties:
                field:
                  type: "text"
                  fields:
                    vectors:
                      type: "text"
                      term_vector: "with_positions_offsets"
                    postings:
                      type: "text"
                      index_options: "offsets"
                stored:
                  type: "text"
                  store: true
                stored_only:
                  type: "text"
                  store: true
    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"
      id: "1"
      refresh: true
      body:
        nested:
          field: "The quick brown fox is brown."
          stored: "The quick brown fox is brown."
          stored_only: "The quick brown fox is brown."
    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"
---
Unified highlighter:
- do:
    search:
      index: "test"
      body:
        query:
          nested:
            path: "nested"
            query:
              multi_match:
                query: "quick brown fox"
                fields:
                - "nested.field"
                - "nested.field.vectors"
                - "nested.field.postings"
            inner_hits:
              highlight:
                type: "unified"
                fields:
                  nested.field: {}
                  nested.field.vectors: {}
                  nested.field.postings: {}
    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.0.highlight.nested\.field.0: "The <em>quick</em>\
      \ <em>brown</em> <em>fox</em> is <em>brown</em>."
- match:
    hits.hits.0.inner_hits.nested.hits.hits.0.highlight.nested\.field\.vectors.0: "The\
      \ <em>quick</em> <em>brown</em> <em>fox</em> is <em>brown</em>."
- match:
    hits.hits.0.inner_hits.nested.hits.hits.0.highlight.nested\.field\.postings.0: "The\
      \ <em>quick</em> <em>brown</em> <em>fox</em> is <em>brown</em>."
---
Unified highlighter with stored fields:
- do:
    search:
      index: "test"
      body:
        query:
          nested:
            path: "nested"
            query:
              multi_match:
                query: "quick brown fox"
                fields:
                - "nested.stored"
                - "nested.stored_only"
            inner_hits:
              highlight:
                type: "unified"
                fields:
                  nested.stored: {}
                  nested.stored_only: {}
    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.0.highlight.nested\.stored.0: "The <em>quick</em>\
      \ <em>brown</em> <em>fox</em> is <em>brown</em>."
- match:
    hits.hits.0.inner_hits.nested.hits.hits.0.highlight.nested\.stored_only.0: "The\
      \ <em>quick</em> <em>brown</em> <em>fox</em> is <em>brown</em>."
---
Unified highlighter with stored fields and disabled source:
- requires:
    cluster_features: "gte_v7.10.2"
    reason: "bug fix introduced in 7.10.2"
- do:
    indices.create:
      index: "disabled_source"
      body:
        mappings:
          _source:
            enabled: false
          properties:
            nested:
              type: "nested"
              properties:
                field:
                  type: "text"
                stored_only:
                  type: "text"
                  store: true
    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: "disabled_source"
      id: "1"
      refresh: true
      body:
        nested:
          field: "The quick brown fox is brown."
          stored_only: "The quick brown fox is brown."
    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:
    search:
      index: "disabled_source"
      body:
        query:
          nested:
            path: "nested"
            query:
              multi_match:
                query: "quick brown fox"
                fields:
                - "nested.field"
                - "nested.stored_only"
            inner_hits:
              highlight:
                type: "unified"
                fields:
                  nested.field: {}
                  nested.stored_only: {}
    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"
- is_false: "hits.hits.0.inner_hits.nested.hits.hits.0.highlight.nested\\.field"
- match:
    hits.hits.0.inner_hits.nested.hits.hits.0.highlight.nested\.stored_only.0: "The\
      \ <em>quick</em> <em>brown</em> <em>fox</em> is <em>brown</em>."
