---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "datafeeds-crud-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"analysis_config\" : {\n  \
        \    \"bucket_span\": \"1h\",\n      \"detectors\" :[{\"function\":\"count\"\
        }],\n      \"summary_count_field_name\": \"doc_count\"\n  },\n  \"data_description\"\
        \ : {\n      \"format\":\"xcontent\",\n      \"time_field\":\"time\",\n  \
        \    \"time_format\":\"epoch\"\n  }\n}\n"
    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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_job:
      job_id: "datafeeds-crud-2"
      body: "{\n  \"analysis_config\" : {\n      \"bucket_span\": \"1h\",\n      \"\
        detectors\" :[{\"function\":\"count\"}]\n  },\n  \"data_description\" : {\n\
        \      \"time_field\":\"time\"\n  }\n}\n"
    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 get all datafeeds and stats given no datafeed exists:
- do:
    ml.get_datafeeds:
      datafeed_id: "_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:
    count: 0
- match:
    datafeeds: []
- do:
    ml.get_datafeed_stats:
      datafeed_id: "_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:
    count: 0
- match:
    datafeeds: []
---
Test get datafeed with expression that does not match and allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    ml.get_datafeeds:
      datafeed_id: "missing-*"
      allow_no_match: 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"
- match:
    count: 0
- match:
    datafeeds: []
---
Test get datafeed with expression that does not match and not allow_no_match:
- skip:
    features:
    - "warnings"
- do:
    catch: "missing"
    ml.get_datafeeds:
      datafeed_id: "missing-*"
      allow_no_match: false
    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 put datafeed referring to missing job_id:
- do:
    catch: "/resource_not_found_exception/"
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"a-missing-job\",\n  \"indexes\":[\"index-foo\"]\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"
---
Test put datafeed with security headers in the body:
- do:
    catch: "/unknown field \\[headers\\]/"
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indices\":[\"index-foo\"],\n\
        \  \"headers\":{ \"a_security_header\" : \"secret\" }\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"
---
Test put datafeed referring to existing job_id:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-1"
- match:
    job_id: "datafeeds-crud-1"
- match:
    indices:
    - "index-foo"
- match:
    scroll_size: 1000
- is_true: "query.match_all"
- match:
    chunking_config:
      mode: "auto"
- is_true: "authorization.roles"
---
Test put datafeed whose id is already taken:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-1"
- do:
    catch: "/resource_already_exists_exception/"
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-2\",\n  \"indexes\":[\"index-foo\"]\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"
---
Test put datafeed with job_id that is already used by another datafeed:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-1"
- do:
    catch: "/A datafeed \\[test-datafeed-1\\] already exists for job \\[datafeeds-crud-1\\\
      ]/"
    ml.put_datafeed:
      datafeed_id: "test-datafeed-2"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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"
---
Test put datafeed with invalid query:
- do:
    catch: "/failed\\sto\\sparse\\sfield\\s\\[query\\]/"
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"],\n\
        \  \"query\":{\"match_all_misspelled\":{}}\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"
---
Test update datafeed:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"],\n\
        \  \"scroll_size\": 2000,\n  \"frequency\": \"1m\",\n  \"query_delay\": \"\
        30s\",\n  \"max_empty_searches\": 42\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:
    max_empty_searches: 42
- do:
    ml.update_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"indexes\":[\"index-*\"],\n  \"scroll_size\": 10000,\n  \"frequency\"\
        : \"2m\",\n  \"query_delay\": \"0s\",\n  \"max_empty_searches\": -1\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:
    datafeed_id: "test-datafeed-1"
- match:
    job_id: "datafeeds-crud-1"
- match:
    indices:
    - "index-*"
- match:
    scroll_size: 10000
- match:
    frequency: "2m"
- match:
    query_delay: "0s"
- is_false: "max_empty_searches"
- is_true: "authorization.roles"
---
Test update datafeed to point to different job:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"],\n\
        \  \"scroll_size\": 2000\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:
    job_id: "datafeeds-crud-1"
- do:
    ml.update_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\": \"datafeeds-crud-1\"\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:
    job_id: "datafeeds-crud-1"
- do:
    catch: "/Datafeed's job_id cannot be changed/"
    ml.update_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\": \"datafeeds-crud-2\"\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"
---
Test update datafeed with missing id:
- do:
    catch: "/resource_not_found_exception/"
    ml.update_datafeed:
      datafeed_id: "a-missing-datafeed"
      body: "{}\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"
---
Test update datafeed to point to missing job:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"],\n\
        \  \"scroll_size\": 2000\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"
- do:
    catch: "/Datafeed's job_id cannot be changed/"
    ml.update_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\": \"update-datafeed-missing-job\"\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"
---
Test update datafeed to point to job already attached to another datafeed:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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"
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-2"
      body: "{\n  \"job_id\":\"datafeeds-crud-2\",\n  \"indexes\":[\"index-foo\"]\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"
- do:
    catch: "/Datafeed's job_id cannot be changed/"
    ml.update_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\": \"datafeeds-crud-2\"\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"
---
Test delete datafeed with missing id:
- do:
    catch: "/resource_not_found_exception/"
    ml.delete_datafeed:
      datafeed_id: "a-missing-datafeed"
    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 put datafeed with chunking_config:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indices\":[\"index-foo\"],\n\
        \  \"chunking_config\": {\"mode\":\"manual\",\"time_span\": \"1h\"}\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:
    datafeed_id: "test-datafeed-1"
- match:
    chunking_config.mode: "manual"
- match:
    chunking_config.time_span: "1h"
---
Test put datafeed with aggregations:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-aggs-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indices\":[\"index-foo\"],\n\
        \  \"aggs\": {\n    \"histogram_buckets\":{\n      \"date_histogram\": {\n\
        \        \"field\": \"@timestamp\",\n        \"fixed_interval\": \"5m\",\n\
        \        \"time_zone\": \"UTC\",\n        \"min_doc_count\": 0\n      },\n\
        \      \"aggs\": {\n        \"@timestamp\": {\n           \"max\": {\n   \
        \           \"field\": \"@timestamp\"\n           }\n        },\n        \"\
        bytes_in_avg\": {\n          \"avg\": {\n             \"field\": \"system.network.in.bytes\"\
        \n          }\n        },\n        \"bytes_in_derivative\": {\n          \"\
        derivative\": {\n            \"buckets_path\": \"bytes_in_avg\"\n        \
        \  }\n        },\n        \"non_negative_bytes\": {\n          \"bucket_script\"\
        : {\n            \"buckets_path\": {\n              \"bytes\": \"bytes_in_derivative\"\
        \n            },\n            \"script\": \"params.bytes > 0 ? params.bytes\
        \ : null\"\n          }\n        }\n      }\n    }\n  },\n  \"max_empty_searches\"\
        : -1\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"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-datafeed-aggs-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:
    datafeeds.0.datafeed_id: "test-datafeed-aggs-1"
- match:
    datafeeds.0.aggregations.histogram_buckets.date_histogram.field: "@timestamp"
- match:
    datafeeds.0.aggregations.histogram_buckets.aggs.@timestamp.max.field: "@timestamp"
- match:
    datafeeds.0.aggregations.histogram_buckets.aggs.bytes_in_avg.avg.field: "system.network.in.bytes"
- match:
    datafeeds.0.aggregations.histogram_buckets.aggs.non_negative_bytes.bucket_script.buckets_path.bytes: "bytes_in_derivative"
- is_false: "max_empty_searches"
- is_true: "datafeeds.0.authorization.roles"
---
Test delete datafeed:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-1"
- do:
    ml.delete_datafeed:
      datafeed_id: "test-datafeed-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:
    acknowledged: true
---
Test force delete datafeed:
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-1"
- do:
    ml.delete_datafeed:
      datafeed_id: "test-datafeed-1"
      force: 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"
- match:
    acknowledged: true
---
Test put and update datafeed with indices options:
- skip:
    features: "warnings"
- do:
    ml.put_datafeed:
      datafeed_id: "test-datafeed-indices-options-1"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"],\n\
        \  \"indices_options\": {\n     \"expand_wildcards\": [\"closed\", \"open\"\
        ],\n     \"ignore_throttled\": false\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"
- match:
    datafeed_id: "test-datafeed-indices-options-1"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-datafeed-indices-options-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:
    datafeeds.0.indices_options.ignore_throttled: false
- length:
    datafeeds.0.indices_options.expand_wildcards: 2
- match:
    datafeeds.0.indices_options.expand_wildcards.0: "open"
- match:
    datafeeds.0.indices_options.expand_wildcards.1: "closed"
- do:
    ml.update_datafeed:
      datafeed_id: "test-datafeed-indices-options-1"
      body: "{\n   \"indices_options\": {\n      \"ignore_throttled\": true\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"
- match:
    datafeed_id: "test-datafeed-indices-options-1"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-datafeed-indices-options-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:
    datafeeds.0.indices_options.ignore_throttled: true
---
Test put and update datafeed with indices options in params:
- skip:
    features: "warnings"
- do:
    warnings:
    - "[ignore_throttled] parameter is deprecated because frozen indices have been\
      \ deprecated. Consider cold or frozen tiers in place of frozen indices."
    ml.put_datafeed:
      datafeed_id: "test-datafeed-indices-options-params-1"
      ignore_throttled: false
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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:
    datafeed_id: "test-datafeed-indices-options-params-1"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-datafeed-indices-options-params-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:
    datafeeds.0.indices_options.ignore_throttled: false
- do:
    warnings:
    - "[ignore_throttled] parameter is deprecated because frozen indices have been\
      \ deprecated. Consider cold or frozen tiers in place of frozen indices."
    ml.update_datafeed:
      datafeed_id: "test-datafeed-indices-options-params-1"
      ignore_throttled: false
      allow_no_indices: false
      body: "{ }\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:
    datafeed_id: "test-datafeed-indices-options-params-1"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-datafeed-indices-options-params-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:
    datafeeds.0.indices_options.ignore_throttled: false
- match:
    datafeeds.0.indices_options.allow_no_indices: false
---
Test get datafeed for export:
- do:
    ml.put_datafeed:
      datafeed_id: "test-for-export"
      body: "{\n  \"job_id\":\"datafeeds-crud-1\",\n  \"indexes\":[\"index-foo\"]\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"
- do:
    ml.get_datafeeds:
      datafeed_id: "test-for-export"
      exclude_generated: 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"
- match:
    datafeeds.0.indices.0: "index-foo"
- is_false: "datafeeds.0.create_time"
- is_false: "datafeeds.0.query_delay"
- is_false: "datafeeds.0.chunking_config"
