---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "bar"
      body:
        mappings:
          properties:
            baz:
              type: "keyword"
            a:
              type: "keyword"
            b:
              type: "keyword"
    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"
---
Test enrich crud apis:
- do:
    enrich.put_policy:
      name: "policy-crud"
      body:
        match:
          indices:
          - "bar*"
          match_field: "baz"
          enrich_fields:
          - "a"
          - "b"
    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"
- is_true: "acknowledged"
- do:
    enrich.execute_policy:
      name: "policy-crud"
    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:
    status.phase: "COMPLETE"
- do:
    enrich.get_policy:
      name: "policy-crud"
    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"
- length:
    policies: 1
- match:
    policies.0.config.match.name: "policy-crud"
- match:
    policies.0.config.match.indices:
    - "bar*"
- match:
    policies.0.config.match.match_field: "baz"
- match:
    policies.0.config.match.enrich_fields:
    - "a"
    - "b"
- do:
    enrich.get_policy: {}
    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"
- length:
    policies: 1
- match:
    policies.0.config.match.name: "policy-crud"
- match:
    policies.0.config.match.indices:
    - "bar*"
- match:
    policies.0.config.match.match_field: "baz"
- match:
    policies.0.config.match.enrich_fields:
    - "a"
    - "b"
- do:
    enrich.stats: {}
    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"
- length:
    executing_policies: 0
- length:
    coordinator_stats: 1
- match:
    coordinator_stats.0.queue_size: 0
- match:
    coordinator_stats.0.remote_requests_current: 0
- gte:
    coordinator_stats.0.remote_requests_total: 0
- gte:
    coordinator_stats.0.executed_searches_total: 0
- do:
    enrich.delete_policy:
      name: "policy-crud"
    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"
- is_true: "acknowledged"
---
Test using the deprecated elasticsearch_version field results in a warning:
- requires:
    cluster_features:
    - "gte_v8.12.0"
    reason: "elasticsearch_version field deprecated in 8.12.0, to be removed in 9.0"
    test_runner_features: "warnings"
- do:
    warnings:
    - "the [elasticsearch_version] field of an enrich policy has no effect and will\
      \ be removed in a future version of Elasticsearch"
    enrich.put_policy:
      name: "policy-crud-warning"
      body:
        match:
          indices:
          - "bar*"
          match_field: "baz"
          enrich_fields:
          - "a"
          - "b"
          elasticsearch_version: "any string here is acceptable"
    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"
- is_true: "acknowledged"
- do:
    enrich.delete_policy:
      name: "policy-crud-warning"
    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"
- is_true: "acknowledged"
