---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "index-source"
    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:
    headers:
      Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA=="
      Content-Type: "application/vnd.elasticsearch+json;compatible-with=8"
      Accept: "application/vnd.elasticsearch+json;compatible-with=8"
    ml.put_trained_model:
      model_id: "a-regression-model-0"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"tags\": [\"regression\"\
        , \"tag1\"],\n  \"inference_config\": {\"regression\":{}},\n  \"input\": {\"\
        field_names\": [\"field1\", \"field2\"]},\n  \"definition\": {\n     \"preprocessors\"\
        : [],\n     \"trained_model\": {\n        \"tree\": {\n           \"feature_names\"\
        : [\"field1\", \"field2\"],\n           \"tree_structure\": [\n          \
        \    {\"node_index\": 0, \"leaf_value\": 1}\n           ],\n           \"\
        target_type\": \"regression\"\n        }\n     }\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_trained_model:
      model_id: "a-regression-model-1"
      body: "{\n  \"description\": \"empty model for tests\",\n  \"model_type\": \"\
        tree_ensemble\",\n  \"inference_config\": {\"regression\":{}},\n  \"input\"\
        : {\"field_names\": [\"field1\", \"field2\"]},\n  \"definition\": {\n    \
        \ \"preprocessors\": [],\n     \"trained_model\": {\n        \"tree\": {\n\
        \           \"feature_names\": [\"field1\", \"field2\"],\n           \"tree_structure\"\
        : [\n              {\"node_index\": 0, \"leaf_value\": 1}\n           ],\n\
        \           \"target_type\": \"regression\"\n        }\n     }\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_data_frame_analytics:
      id: "prepackaged"
      body: "{\n  \"source\": {\n    \"index\": \"index-source\"\n  },\n  \"dest\"\
        : {\n    \"index\": \"index-dest\"\n  },\n  \"analysis\": {\"regression\"\
        :{\n      \"dependent_variable\": \"to_predict\"\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 cat trained models:
- do:
    cat.ml_trained_models:
      model_id: "a-regression-model-0"
    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:
    $body: "/ #id\\s+heap_size\\s+operations\\s+create_time\\s+type\\s+ingest.pipelines\\\
      s+data_frame.id\n^ (a-regression-model-0\\s+\\w+\\s+\\d+\\s+.*?\\s+[a-z_]+\\\
      s+\\d+.*?\\n)+  $/\n"
- do:
    cat.ml_trained_models:
      v: true
      model_id: "a-regression-model-0"
    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:
    $body: "/id\\s+heap_size\\s+operations\\s+create_time\\s+type\\s+ingest\\.pipelines\\\
      s+data_frame\\.id\\s*\\n\n(a-regression-model-0\\s+\\w+\\s+\\d+\\s+.*?\\s+tree_ensemble\\\
      s+\\d+\\s+\\w+\\n)+$/\n"
- do:
    cat.ml_trained_models:
      h: "id,license,dfid,ip"
      v: true
    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:
    $body: "/^  id                        \\s+  license \\s+ dfid         \\s+ ip\
      \   \\n\n   (a-regression-model-0      \\s+  \\w+     \\s+ __none__     \\s+\
      \ \\d+  \\n)+\n   (a-regression-model-1      \\s+  \\w+     \\s+ __none__  \
      \   \\s+ \\d+  \\n)+\n   (lang_ident_model_1        \\s+  \\w+     \\s+ prepackaged\
      \  \\s+ \\d+  \\n)+  $/\n"
- do:
    cat.ml_trained_models:
      model_id: "a-regression-model-1"
      h: "id,license,dfid,ip"
      v: true
    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:
    $body: "/^  id                        \\s+  license \\s+ dfid         \\s+ ip\
      \   \\n\n   (a-regression-model-1      \\s+  \\w+     \\s+ __none__     \\s+\
      \ \\d+  \\n)+ $/\n"
