---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "source"
      body:
        mappings:
          properties:
            baz:
              type: "keyword"
            a:
              type: "keyword"
            b:
              type: "keyword"
        aliases:
          myalias: {}
    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:
    bulk:
      refresh: true
      index: "source"
      body:
      - "{\"index\": {}}"
      - "{\"baz\": \"quick\", \"a\": \"brown\", \"b\": \"fox\"}"
      - "{\"index\": {}}"
      - "{\"baz\": \"lazy\", \"a\": \"dog\"}"
    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:
    enrich.put_policy:
      name: "test_policy"
      body:
        match:
          indices:
          - "source*"
          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"
- do:
    enrich.execute_policy:
      name: "test_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"
- do:
    ingest.put_pipeline:
      id: "test_pipeline"
      body:
        processors:
        - enrich:
            policy_name: "test_policy"
            field: "baz"
            target_field: "target"
    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"
---
teardown:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    ingest.delete_pipeline:
      id: "test_pipeline"
    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:
    enrich.delete_policy:
      name: "test_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"
---
enrich documents over _bulk:
- do:
    bulk:
      refresh: true
      index: "target"
      pipeline: "test_pipeline"
      body:
      - "{\"index\": {\"_id\": \"1\"}}"
      - "{\"baz\": \"quick\", \"c\": 1}"
      - "{\"index\": {\"_id\": \"2\"}}"
      - "{\"baz\": \"lazy\", \"c\": 2}"
      - "{\"index\": {\"_id\": \"3\"}}"
      - "{\"baz\": \"slow\", \"c\": 3}"
    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:
    get:
      index: "target"
      id: "1"
    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:
    _source:
      baz: "quick"
      target:
        baz: "quick"
        a: "brown"
        b: "fox"
      c: 1
- do:
    get:
      index: "target"
      id: "2"
    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:
    _source:
      baz: "lazy"
      target:
        baz: "lazy"
        a: "dog"
      c: 2
- do:
    get:
      index: "target"
      id: "3"
    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:
    _source:
      baz: "slow"
      c: 3
---
enrich documents over _bulk via an alias:
- do:
    enrich.put_policy:
      name: "test_alias_policy"
      body:
        match:
          indices:
          - "myalias"
          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"
- do:
    enrich.execute_policy:
      name: "test_alias_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"
- do:
    ingest.put_pipeline:
      id: "test_alias_pipeline"
      body:
        processors:
        - enrich:
            policy_name: "test_alias_policy"
            field: "baz"
            target_field: "target"
    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:
    bulk:
      refresh: true
      index: "target"
      pipeline: "test_alias_pipeline"
      body:
      - "{\"index\": {\"_id\": \"1\"}}"
      - "{\"baz\": \"quick\", \"c\": 1}"
      - "{\"index\": {\"_id\": \"2\"}}"
      - "{\"baz\": \"lazy\", \"c\": 2}"
      - "{\"index\": {\"_id\": \"3\"}}"
      - "{\"baz\": \"slow\", \"c\": 3}"
    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:
    errors: false
- do:
    get:
      index: "target"
      id: "1"
    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:
    _source:
      baz: "quick"
      target:
        baz: "quick"
        a: "brown"
        b: "fox"
      c: 1
- do:
    get:
      index: "target"
      id: "2"
    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:
    _source:
      baz: "lazy"
      target:
        baz: "lazy"
        a: "dog"
      c: 2
- do:
    get:
      index: "target"
      id: "3"
    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:
    _source:
      baz: "slow"
      c: 3
- do:
    ingest.delete_pipeline:
      id: "test_alias_pipeline"
    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:
    enrich.delete_policy:
      name: "test_alias_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"
---
enrich stats REST response structure:
- requires:
    test_runner_features:
    - "capabilities"
    capabilities:
    - method: "GET"
      path: "/_enrich/stats"
      capabilities:
      - "size-in-bytes"
    reason: "Capability required to run test"
- do:
    ingest.simulate:
      id: "test_pipeline"
      body: "{\n  \"docs\": [\n    {\n      \"_index\": \"enrich-cache-stats-index\"\
        ,\n      \"_id\": \"1\",\n      \"_source\": {\"baz\": \"quick\", \"c\": 1}\n\
        \    },\n    {\n      \"_index\": \"enrich-cache-stats-index\",\n      \"\
        _id\": \"2\",\n      \"_source\": {\"baz\": \"lazy\", \"c\": 2}\n    },\n\
        \    {\n      \"_index\": \"enrich-cache-stats-index\",\n      \"_id\": \"\
        3\",\n      \"_source\": {\"baz\": \"slow\", \"c\": 3}\n    }\n  ]\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"
- length:
    docs: 3
- 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"
- exists: "executing_policies"
- is_true: "coordinator_stats"
- is_true: "coordinator_stats.0.node_id"
- exists: "coordinator_stats.0.queue_size"
- exists: "coordinator_stats.0.remote_requests_current"
- exists: "coordinator_stats.0.remote_requests_total"
- exists: "coordinator_stats.0.executed_searches_total"
- is_true: "cache_stats"
- is_true: "cache_stats.0.node_id"
- exists: "cache_stats.0.count"
- exists: "cache_stats.0.hits"
- exists: "cache_stats.0.misses"
- exists: "cache_stats.0.evictions"
- exists: "cache_stats.0.hits_time_in_millis"
- exists: "cache_stats.0.misses_time_in_millis"
- exists: "cache_stats.0.size_in_bytes"
