---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    snapshot.create_repository:
      repository: "test_repo_restore_1"
      body:
        type: "source"
        settings:
          delegate_type: "fs"
          location: "test_repo_restore_1_loc"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.create:
      index: "test_index"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    cluster.health:
      wait_for_status: "green"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
---
Create a source only snapshot and then restore it:
- skip:
    features:
    - "allowed_warnings"
- do:
    index:
      index: "test_index"
      id: "1"
      body:
        foo: "bar"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.flush:
      index: "test_index"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.create:
      repository: "test_repo_restore_1"
      snapshot: "test_snapshot"
      wait_for_completion: true
      body: "{ \"indices\": \"test_index\" }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "test_snapshot"
- match:
    snapshot.state: "SUCCESS"
- match:
    snapshot.shards.successful: 1
- match:
    snapshot.shards.failed: 0
- is_true: "snapshot.version"
- gt:
    snapshot.version_id: 0
- do:
    indices.close:
      index: "test_index"
    allowed_warnings:
    - "the default value for the ?wait_for_active_shards parameter will change from\
      \ '0' to 'index-setting' in version 8; specify '?wait_for_active_shards=index-setting'\
      \ to adopt the future default behaviour, or '?wait_for_active_shards=0' to preserve\
      \ today's behaviour"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.restore:
      repository: "test_repo_restore_1"
      snapshot: "test_snapshot"
      wait_for_completion: true
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    indices.recovery:
      index: "test_index"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    test_index.shards.0.type: "SNAPSHOT"
- match:
    test_index.shards.0.stage: "DONE"
- match:
    test_index.shards.0.translog.recovered: 0
- match:
    test_index.shards.0.translog.total: 0
- match:
    test_index.shards.0.translog.total_on_start: 0
- gte:
    test_index.shards.0.index.files.recovered: 5
- lte:
    test_index.shards.0.index.files.recovered: 6
- match:
    test_index.shards.0.index.files.reused: 0
- match:
    test_index.shards.0.index.size.reused_in_bytes: 0
- gt:
    test_index.shards.0.index.size.recovered_in_bytes: 0
- do:
    search:
      rest_total_hits_as_int: true
      index: "test_index"
      body:
        query:
          match_all: {}
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    hits.total: 1
- length:
    hits.hits: 1
- match:
    hits.hits.0._id: "1"
---
Failed to snapshot indices with synthetic source:
- skip:
    features:
    - "allowed_warnings"
- requires:
    cluster_features:
    - "mapper.source.mode_from_index_setting"
    reason: "Source mode configured through index setting"
- do:
    indices.create:
      index: "test_synthetic"
      body:
        settings:
          number_of_shards: 1
          number_of_replicas: 0
          index:
            mapping.source.mode: "synthetic"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- do:
    snapshot.create:
      repository: "test_repo_restore_1"
      snapshot: "test_snapshot_2"
      wait_for_completion: true
      body: "{ \n  \"indices\": \"test_synthetic\",\n  \"include_global_state\": false\n\
        }\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "test_snapshot_2"
- match:
    snapshot.state: "PARTIAL"
- match:
    snapshot.shards.successful: 0
- match:
    snapshot.shards.failed: 1
- match:
    snapshot.failures.0.index: "test_synthetic"
- match:
    snapshot.failures.0.reason: "IllegalStateException[Can't snapshot _source only\
      \ on an index that has incomplete source ie. has _source disabled or filters\
      \ the source]"
- is_true: "snapshot.version"
- gt:
    snapshot.version_id: 0
- do:
    snapshot.create:
      repository: "test_repo_restore_1"
      snapshot: "test_snapshot_3"
      wait_for_completion: true
      body: "{ \n  \"indices\": \"test_*\",\n  \"include_global_state\": false\n}\n"
    headers:
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    allowed_warnings_regex:
    - ".*rollup functionality will be removed in Elasticsearch.*"
    - "Index \\[\\.profiling-.*\\] name begins with a dot.* and will not be allowed\
      \ in a future Elasticsearch version."
    - "Parameter \\[default_metric\\] is deprecated and will be removed in a future\
      \ version"
- match:
    snapshot.snapshot: "test_snapshot_3"
- match:
    snapshot.state: "PARTIAL"
- match:
    snapshot.shards.successful: 1
- match:
    snapshot.shards.failed: 1
- match:
    snapshot.failures.0.index: "test_synthetic"
- match:
    snapshot.failures.0.reason: "IllegalStateException[Can't snapshot _source only\
      \ on an index that has incomplete source ie. has _source disabled or filters\
      \ the source]"
- is_true: "snapshot.version"
- gt:
    snapshot.version_id: 0
