setup:
  - requires:
      cluster_features: [ "mapper.source.mode_from_index_setting" ]
      reason: "Source mode configured through index setting"

  - do:
      indices.create:
        index: synthetic
        body:
          settings:
            index:
              mapping.source.mode: synthetic
          mappings:
            properties:
              kwd:
                type: keyword

  - do:
      indices.create:
        index: standard
        body:
          mappings:
            properties:
              kwd:
                type: keyword

---
from synthetic:
  - requires:
      cluster_features: ["gte_v8.3.0"]
      reason: introduced in 8.3.0

  - do:
      bulk:
        refresh: true
        index: synthetic
        body:
          - '{"index": {}}'
          - '{"kwd": "aaa"}'
          - '{"index": {}}'
          - '{"kwd": "bbb"}'
          - '{"index": {}}'
          - '{"kwd": "ccc"}'
          - '{"index": {}}'
          - '{"kwd": "ddd"}'
          - '{"index": {}}'
          - '{"kwd": "eee"}'

  - do:
      reindex:
        refresh: true
        body:
          source:
            index: synthetic
          dest:
            index: standard
  - match: {created: 5}
  - match: {updated: 0}
  - match: {version_conflicts: 0}
  - match: {batches: 1}
  - match: {failures: []}
  - match: {throttled_millis: 0}
  - gte: { took: 0 }
  - is_false: task
  - is_false: deleted

  - do:
      search:
        index: standard
        body:
          sort:
            - kwd: asc
  - match: { hits.total.value: 5 }
  - match:
      hits.hits.0._source:
        kwd: aaa
  - match:
      hits.hits.1._source:
        kwd: bbb
  - match:
      hits.hits.2._source:
        kwd: ccc
  - match:
      hits.hits.3._source:
        kwd: ddd
  - match:
      hits.hits.4._source:
        kwd: eee

---
from standard:
  - requires:
      cluster_features: ["gte_v8.3.0"]
      reason: introduced in 8.3.0

  - do:
      bulk:
        refresh: true
        index: standard
        body:
          - '{"index": {}}'
          - '{"kwd": "aaa"}'
          - '{"index": {}}'
          - '{"kwd": "bbb"}'
          - '{"index": {}}'
          - '{"kwd": "ccc"}'
          - '{"index": {}}'
          - '{"kwd": "ddd"}'
          - '{"index": {}}'
          - '{"kwd": "eee"}'

  - do:
      reindex:
        refresh: true
        body:
          source:
            index: standard
          dest:
            index: synthetic
  - match: {created: 5}
  - match: {updated: 0}
  - match: {version_conflicts: 0}
  - match: {batches: 1}
  - match: {failures: []}
  - match: {throttled_millis: 0}
  - gte: { took: 0 }
  - is_false: task
  - is_false: deleted

  - do:
      search:
        index: synthetic
        body:
          sort:
            - kwd: asc
  - match: { hits.total.value: 5 }
  - match:
      hits.hits.0._source:
        kwd: aaa
  - match:
      hits.hits.1._source:
        kwd: bbb
  - match:
      hits.hits.2._source:
        kwd: ccc
  - match:
      hits.hits.3._source:
        kwd: ddd
  - match:
      hits.hits.4._source:
        kwd: eee
