---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
---
Test neither job id nor body:
- do:
    catch: "/Please provide a job \\[id\\] or the config object/"
    ml.explain_data_frame_analytics:
      id: ""
    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 both job id and body:
- do:
    catch: "/Please provide either a job \\[id\\] or the config object but not both/"
    ml.explain_data_frame_analytics:
      id: "foo"
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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 missing job:
- do:
    catch: "missing"
    ml.explain_data_frame_analytics:
      id: "no_such_job"
    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 id that matches multiple jobs:
- 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:
    ml.put_data_frame_analytics:
      id: "foo-1"
      body: "{\n  \"source\": {\n    \"index\": \"index-source\"\n  },\n  \"dest\"\
        : {\n    \"index\": \"index-dest\"\n  },\n  \"analysis\": {\"outlier_detection\"\
        :{}}\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_data_frame_analytics:
      id: "foo-2"
      body: "{\n  \"source\": {\n    \"index\": \"index-source\"\n  },\n  \"dest\"\
        : {\n    \"index\": \"index-dest\"\n  },\n  \"analysis\": {\"outlier_detection\"\
        :{}}\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: "/expected only one config but matched \\[foo-1, foo-2\\]/"
    ml.explain_data_frame_analytics:
      id: "foo-*"
    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 empty data frame given body:
- do:
    indices.create:
      index: "index-source"
      body:
        mappings:
          properties:
            x:
              type: "float"
            "y":
              type: "float"
    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: "/Unable to estimate memory usage as no documents in the source indices\
      \ \\[index-source\\] contained all the fields selected for analysis/"
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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:
    index:
      index: "index-source"
      refresh: true
      body:
        x: 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:
    result: "created"
- do:
    catch: "/Unable to estimate memory usage as no documents in the source indices\
      \ \\[index-source\\] contained all the fields selected for analysis/"
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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 non-empty data frame given body:
- do:
    indices.create:
      index: "index-source"
      body:
        mappings:
          properties:
            x:
              type: "float"
            "y":
              type: "float"
    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:
    index:
      index: "index-source"
      refresh: true
      body:
        x: 1
        "y": 10
    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:
    result: "created"
- do:
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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:
    memory_estimation.expected_memory_without_disk: "/ \\d[km]b /"
- match:
    memory_estimation.expected_memory_with_disk: "/ \\d[km]b /"
- length:
    field_selection: 2
- match:
    field_selection.0.name: "x"
- match:
    field_selection.0.mapping_types:
    - "float"
- match:
    field_selection.0.is_included: true
- match:
    field_selection.0.is_required: false
- match:
    field_selection.0.feature_type: "numerical"
- is_false: "field_selection.0.reason"
- match:
    field_selection.1.name: "y"
- match:
    field_selection.1.mapping_types:
    - "float"
- match:
    field_selection.1.is_included: true
- match:
    field_selection.1.is_required: false
- match:
    field_selection.1.feature_type: "numerical"
- is_false: "field_selection.1.reason"
- do:
    index:
      index: "index-source"
      refresh: true
      body:
        x: 2
        "y": 20
    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:
    result: "created"
- do:
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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:
    memory_estimation.expected_memory_without_disk: "/ \\d[km]b /"
- match:
    memory_estimation.expected_memory_with_disk: "/ \\d[km]b /"
- do:
    index:
      index: "index-source"
      refresh: true
      body:
        x: 3
        "y": 30
    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:
    result: "created"
- do:
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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:
    memory_estimation.expected_memory_without_disk: "/ \\d[km]b /"
- match:
    memory_estimation.expected_memory_with_disk: "/ \\d[km]b /"
---
Test field_selection given body:
- do:
    indices.create:
      index: "index-source"
      body:
        mappings:
          properties:
            field_1:
              type: "integer"
            field_2:
              type: "double"
            field_3:
              type: "date"
    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:
    index:
      index: "index-source"
      refresh: true
      body:
        field_1: 3
        field_2: 3.14
        field_3: "2019-11-11T00:00:00"
        field_4: "blah"
    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:
    result: "created"
- do:
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          regression:
            dependent_variable: "field_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"
- is_true: "memory_estimation.expected_memory_without_disk"
- is_true: "memory_estimation.expected_memory_with_disk"
- length:
    field_selection: 5
- match:
    field_selection.0.name: "field_1"
- match:
    field_selection.0.mapping_types:
    - "integer"
- match:
    field_selection.0.is_included: true
- match:
    field_selection.0.is_required: true
- match:
    field_selection.0.feature_type: "numerical"
- is_false: "field_selection.0.reason"
- match:
    field_selection.1.name: "field_2"
- match:
    field_selection.1.mapping_types:
    - "double"
- match:
    field_selection.1.is_included: true
- match:
    field_selection.1.is_required: false
- match:
    field_selection.1.feature_type: "numerical"
- is_false: "field_selection.1.reason"
- match:
    field_selection.2.name: "field_3"
- match:
    field_selection.2.mapping_types:
    - "date"
- match:
    field_selection.2.is_included: false
- match:
    field_selection.2.is_required: false
- is_false: "field_selection.2.feature_type"
- match:
    field_selection.2.reason: "unsupported type; supported types are [boolean, byte,\
      \ double, float, half_float, integer, ip, keyword, long, scaled_float, short,\
      \ text, unsigned_long]"
- match:
    field_selection.3.name: "field_4"
- match:
    field_selection.3.mapping_types:
    - "text"
- match:
    field_selection.3.is_included: false
- match:
    field_selection.3.is_required: false
- is_false: "field_selection.3.feature_type"
- match:
    field_selection.3.reason: "[field_4.keyword] is preferred because it is aggregatable"
- match:
    field_selection.4.name: "field_4.keyword"
- match:
    field_selection.4.mapping_types:
    - "keyword"
- match:
    field_selection.4.is_included: true
- match:
    field_selection.4.is_required: false
- match:
    field_selection.4.feature_type: "categorical"
- is_false: "field_selection.4.reason"
---
Test field_selection given job:
- do:
    indices.create:
      index: "index-source"
      body:
        mappings:
          properties:
            field_1:
              type: "integer"
            field_2:
              type: "double"
            field_3:
              type: "date"
    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:
    index:
      index: "index-source"
      refresh: true
      body:
        field_1: 3
        field_2: 3.14
        field_3: "2019-11-11T00:00:00"
        field_4: "blah"
    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:
    result: "created"
- do:
    ml.put_data_frame_analytics:
      id: "got-a-job-for-this-one"
      body: "{\n  \"source\": {\n    \"index\": \"index-source\"\n  },\n  \"dest\"\
        : {\n    \"index\": \"index-dest\"\n  },\n  \"analysis\": {\"regression\"\
        :{ \"dependent_variable\": \"field_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.explain_data_frame_analytics:
      id: "got-a-job-for-this-one"
    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: "memory_estimation.expected_memory_without_disk"
- is_true: "memory_estimation.expected_memory_with_disk"
- length:
    field_selection: 5
- match:
    field_selection.0.name: "field_1"
- match:
    field_selection.0.mapping_types:
    - "integer"
- match:
    field_selection.0.is_included: true
- match:
    field_selection.0.is_required: true
- match:
    field_selection.0.feature_type: "numerical"
- is_false: "field_selection.0.reason"
- match:
    field_selection.1.name: "field_2"
- match:
    field_selection.1.mapping_types:
    - "double"
- match:
    field_selection.1.is_included: true
- match:
    field_selection.1.is_required: false
- match:
    field_selection.1.feature_type: "numerical"
- is_false: "field_selection.1.reason"
- match:
    field_selection.2.name: "field_3"
- match:
    field_selection.2.mapping_types:
    - "date"
- match:
    field_selection.2.is_included: false
- match:
    field_selection.2.is_required: false
- is_false: "field_selection.2.feature_type"
- match:
    field_selection.2.reason: "unsupported type; supported types are [boolean, byte,\
      \ double, float, half_float, integer, ip, keyword, long, scaled_float, short,\
      \ text, unsigned_long]"
- match:
    field_selection.3.name: "field_4"
- match:
    field_selection.3.mapping_types:
    - "text"
- match:
    field_selection.3.is_included: false
- match:
    field_selection.3.is_required: false
- is_false: "field_selection.3.feature_type"
- match:
    field_selection.3.reason: "[field_4.keyword] is preferred because it is aggregatable"
- match:
    field_selection.4.name: "field_4.keyword"
- match:
    field_selection.4.mapping_types:
    - "keyword"
- match:
    field_selection.4.is_included: true
- match:
    field_selection.4.is_required: false
- match:
    field_selection.4.feature_type: "categorical"
- is_false: "field_selection.4.reason"
---
Test given no included field:
- do:
    indices.create:
      index: "index-source"
      body:
        mappings:
          properties:
            x:
              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"
- do:
    index:
      index: "index-source"
      refresh: true
      body:
        x: "hello!"
    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:
    result: "created"
- do:
    ml.explain_data_frame_analytics:
      body:
        source:
          index: "index-source"
        analysis:
          outlier_detection: {}
    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:
    memory_estimation.expected_memory_without_disk: "0"
- match:
    memory_estimation.expected_memory_with_disk: "0"
- length:
    field_selection: 1
- match:
    field_selection.0.name: "x"
- match:
    field_selection.0.is_included: false
