---
setup:
- skip:
    features:
    - "headers"
    - "allowed_warnings_regex"
- do:
    indices.create:
      index: "airline-data"
      body:
        mappings:
          properties:
            time:
              type: "date"
            airline:
              type: "keyword"
            responsetime:
              type: "float"
            agg_metric:
              type: "aggregate_metric_double"
              metrics:
              - "min"
              - "max"
              default_metric: "max"
            event_rate:
              type: "integer"
            _isDeleted:
              type: "boolean"
    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: "airline-data"
      id: "1"
      body: "{\n  \"time\": \"2017-02-18T00:00:00Z\",\n  \"airline\": \"foo\",\n \
        \ \"responsetime\": 1.0,\n  \"event_rate\": 5,\n  \"_isDeleted\": false\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:
    index:
      index: "airline-data"
      id: "2"
      body: "{\n  \"time\": \"2017-02-18T00:30:00Z\",\n  \"airline\": \"foo\",\n \
        \ \"responsetime\": 1.0,\n  \"event_rate\": 6,\n  \"_isDeleted\": true\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:
    index:
      index: "airline-data"
      id: "3"
      body: "{\n  \"time\": \"2017-02-18T01:00:00Z\",\n  \"airline\": \"bar\",\n \
        \ \"responsetime\": 42.0,\n  \"event_rate\": 8,\n  \"_isDeleted\": false\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:
    index:
      index: "airline-data"
      id: "4"
      body: "{\n  \"time\": \"2017-02-18T01:01:00Z\",\n  \"airline\": \"foo\",\n \
        \ \"responsetime\": 42.0,\n  \"event_rate\": 7,\n  \"_isDeleted\": true\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:
    indices.refresh:
      index: "airline-data"
    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 preview transform:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"airline\": {\"terms\": {\"field\": \"airline\"\
        }},\n      \"by-hour\": {\"date_histogram\": {\"fixed_interval\": \"1h\",\
        \ \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\": {\"avg\"\
        : {\"field\": \"responsetime\"}},\n      \"time.max\": {\"max\": {\"field\"\
        : \"time\"}},\n      \"time.min\": {\"min\": {\"field\": \"time\"}}\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"
- match:
    preview.0.airline: "foo"
- match:
    preview.0.by-hour: "2017-02-18T00:00:00.000Z"
- match:
    preview.0.avg_response: 1.0
- match:
    preview.0.time.max: "2017-02-18T00:30:00.000Z"
- match:
    preview.0.time.min: "2017-02-18T00:00:00.000Z"
- match:
    preview.1.airline: "bar"
- match:
    preview.1.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.avg_response: 42.0
- match:
    preview.1.time.max: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.time.min: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.airline: "foo"
- match:
    preview.2.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.avg_response: 42.0
- match:
    preview.2.time.max: "2017-02-18T01:01:00.000Z"
- match:
    preview.2.time.min: "2017-02-18T01:01:00.000Z"
- match:
    generated_dest_index.mappings.properties.airline.type: "keyword"
- match:
    generated_dest_index.mappings.properties.by-hour.type: "date"
- match:
    generated_dest_index.mappings.properties.avg_response.type: "double"
- match:
    generated_dest_index.mappings.properties.time\.max.type: "date"
- match:
    generated_dest_index.mappings.properties.time\.min.type: "date"
- do:
    ingest.put_pipeline:
      id: "data_frame_simple_pipeline"
      body: "{\n  \"processors\": [\n   {\n     \"set\" : {\n       \"field\" : \"\
        my_field\",\n       \"value\": 42\n     }\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"
- match:
    acknowledged: true
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"pipeline\"\
        : \"data_frame_simple_pipeline\" },\n  \"pivot\": {\n    \"group_by\": {\n\
        \      \"airline\": {\"terms\": {\"field\": \"airline\"}},\n      \"by-hour\"\
        : {\"date_histogram\": {\"fixed_interval\": \"1h\", \"field\": \"time\"}}},\n\
        \    \"aggs\": {\n      \"avg_response\": {\"avg\": {\"field\": \"responsetime\"\
        }}\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"
- match:
    preview.0.airline: "foo"
- match:
    preview.0.by-hour: "2017-02-18T00:00:00.000Z"
- match:
    preview.0.avg_response: 1.0
- match:
    preview.0.my_field: 42
- match:
    preview.1.airline: "bar"
- match:
    preview.1.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.avg_response: 42.0
- match:
    preview.1.my_field: 42
- match:
    preview.2.airline: "foo"
- match:
    preview.2.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.avg_response: 42.0
- match:
    preview.2.my_field: 42
- match:
    generated_dest_index.mappings.properties.airline.type: "keyword"
- match:
    generated_dest_index.mappings.properties.by-hour.type: "date"
- match:
    generated_dest_index.mappings.properties.avg_response.type: "double"
---
Test preview transform with offset:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"airline\": {\"terms\": {\"field\": \"airline\"\
        }},\n      \"by-hour\": {\"date_histogram\": {\"fixed_interval\": \"1h\",\
        \ \"field\": \"time\", \"offset\": \"-15m\"}}},\n    \"aggs\": {\n      \"\
        avg_response\": {\"avg\": {\"field\": \"responsetime\"}},\n      \"time.max\"\
        : {\"max\": {\"field\": \"time\"}},\n      \"time.min\": {\"min\": {\"field\"\
        : \"time\"}}\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"
- match:
    preview.0.airline: "foo"
- match:
    preview.0.by-hour: "2017-02-17T23:45:00.000Z"
- match:
    preview.0.avg_response: 1.0
- match:
    preview.0.time.max: "2017-02-18T00:30:00.000Z"
- match:
    preview.0.time.min: "2017-02-18T00:00:00.000Z"
- match:
    preview.1.airline: "bar"
- match:
    preview.1.by-hour: "2017-02-18T00:45:00.000Z"
- match:
    preview.1.avg_response: 42.0
- match:
    preview.1.time.max: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.time.min: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.airline: "foo"
- match:
    preview.2.by-hour: "2017-02-18T00:45:00.000Z"
- match:
    preview.2.avg_response: 42.0
- match:
    preview.2.time.max: "2017-02-18T01:01:00.000Z"
- match:
    preview.2.time.min: "2017-02-18T01:01:00.000Z"
- match:
    generated_dest_index.mappings.properties.airline.type: "keyword"
- match:
    generated_dest_index.mappings.properties.by-hour.type: "date"
- match:
    generated_dest_index.mappings.properties.avg_response.type: "double"
- match:
    generated_dest_index.mappings.properties.time\.max.type: "date"
- match:
    generated_dest_index.mappings.properties.time\.min.type: "date"
---
Test preview transform with timeout:
- do:
    transform.preview_transform:
      timeout: "10s"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"airline\": {\"terms\": {\"field\": \"airline\"\
        }},\n      \"by-hour\": {\"date_histogram\": {\"fixed_interval\": \"1h\",\
        \ \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\": {\"avg\"\
        : {\"field\": \"responsetime\"}},\n      \"time.max\": {\"max\": {\"field\"\
        : \"time\"}},\n      \"time.min\": {\"min\": {\"field\": \"time\"}}\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"
---
Test preview transform with disabled mapping deduction:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"airline\": {\"terms\": {\"field\": \"airline\"\
        }},\n      \"by-hour\": {\"date_histogram\": {\"fixed_interval\": \"1h\",\
        \ \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\": {\"avg\"\
        : {\"field\": \"responsetime\"}},\n      \"time.max\": {\"max\": {\"field\"\
        : \"time\"}},\n      \"time.min\": {\"min\": {\"field\": \"time\"}}\n    }\n\
        \  },\n  \"settings\": {\n    \"deduce_mappings\": 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:
    preview.0.airline: "foo"
- match:
    preview.0.by-hour: "2017-02-18T00:00:00.000Z"
- match:
    preview.0.avg_response: 1.0
- match:
    preview.0.time.max: "2017-02-18T00:30:00.000Z"
- match:
    preview.0.time.min: "2017-02-18T00:00:00.000Z"
- match:
    preview.1.airline: "bar"
- match:
    preview.1.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.avg_response: 42.0
- match:
    preview.1.time.max: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.time.min: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.airline: "foo"
- match:
    preview.2.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.avg_response: 42.0
- match:
    preview.2.time.max: "2017-02-18T01:01:00.000Z"
- match:
    preview.2.time.min: "2017-02-18T01:01:00.000Z"
- match:
    generated_dest_index.mappings.properties: {}
---
Test preview transform by id:
- do:
    transform.put_transform:
      transform_id: "airline-transform"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"dest-airline-data-by-airline-and-hour\" },\n  \"pivot\": {\n    \"group_by\"\
        : {\n      \"airline\": {\"terms\": {\"field\": \"airline\"}},\n      \"by-hour\"\
        : {\"date_histogram\": {\"fixed_interval\": \"1h\", \"field\": \"time\"}}},\n\
        \    \"aggs\": {\n      \"avg_response\": {\"avg\": {\"field\": \"responsetime\"\
        }},\n      \"time.max\": {\"max\": {\"field\": \"time\"}},\n      \"time.min\"\
        : {\"min\": {\"field\": \"time\"}}\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"
- match:
    acknowledged: true
- do:
    transform.preview_transform:
      transform_id: "airline-transform"
    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:
    preview.0.airline: "foo"
- match:
    preview.0.by-hour: "2017-02-18T00:00:00.000Z"
- match:
    preview.0.avg_response: 1.0
- match:
    preview.0.time.max: "2017-02-18T00:30:00.000Z"
- match:
    preview.0.time.min: "2017-02-18T00:00:00.000Z"
- match:
    preview.1.airline: "bar"
- match:
    preview.1.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.avg_response: 42.0
- match:
    preview.1.time.max: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.time.min: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.airline: "foo"
- match:
    preview.2.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.avg_response: 42.0
- match:
    preview.2.time.max: "2017-02-18T01:01:00.000Z"
- match:
    preview.2.time.min: "2017-02-18T01:01:00.000Z"
- match:
    generated_dest_index.mappings.properties.airline.type: "keyword"
- match:
    generated_dest_index.mappings.properties.by-hour.type: "date"
- match:
    generated_dest_index.mappings.properties.avg_response.type: "double"
- match:
    generated_dest_index.mappings.properties.time\.max.type: "date"
- match:
    generated_dest_index.mappings.properties.time\.min.type: "date"
---
Test preview transform latest:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"latest\": {\n\
        \    \"unique_key\": [\"airline\"],\n    \"sort\": \"time\"\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:
    $body: 2
- match:
    preview.0.airline: "bar"
- match:
    preview.0.time: "2017-02-18T01:00:00Z"
- is_false: "preview.0._isDeleted"
- match:
    preview.1.airline: "foo"
- match:
    preview.1.time: "2017-02-18T01:01:00Z"
- match:
    generated_dest_index.mappings.properties: {}
- is_false: "preview.1._isDeleted"
- do:
    ingest.put_pipeline:
      id: "transform_latest_simple_pipeline"
      body: "{\n  \"processors\": [\n   {\n     \"set\" : {\n       \"field\" : \"\
        my_field\",\n       \"value\": 42\n     }\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"
- match:
    acknowledged: true
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"pipeline\"\
        : \"transform_latest_simple_pipeline\" },\n  \"latest\": {\n    \"unique_key\"\
        : [\"airline\"],\n    \"sort\": \"time\"\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:
    $body: 2
- match:
    preview.0.airline: "bar"
- match:
    preview.0.time: "2017-02-18T01:00:00Z"
- match:
    preview.0.my_field: 42
- is_false: "preview.0._isDeleted"
- match:
    preview.1.airline: "foo"
- match:
    preview.1.time: "2017-02-18T01:01:00Z"
- match:
    preview.1.my_field: 42
- is_false: "preview.1._isDeleted"
- match:
    generated_dest_index.mappings.properties: {}
---
Test preview non-existent transform:
- do:
    catch: "/Transform with id \\[non-existent-transform\\] could not be found/"
    transform.preview_transform:
      transform_id: "non-existent-transform"
    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 preview without id and body:
- do:
    catch: "/Please provide a transform \\[id\\] or the config object/"
    transform.preview_transform: {}
    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 preview with both id and body:
- do:
    catch: "/Please provide either a transform \\[id\\] or the config object but not\
      \ both/"
    transform.preview_transform:
      transform_id: "non-existent-transform"
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"pipeline\"\
        : \"transform_latest_simple_pipeline\" },\n  \"latest\": {\n    \"unique_key\"\
        : [\"airline\"],\n    \"sort\": \"time\"\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"
---
Test preview transform with invalid config:
- do:
    catch: "/\\[data_frame_terms_group\\] unknown field \\[not_a_terms_param\\]/"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\"airline\": {\"terms\": {\"not_a_terms_param\": \"airline\"\
        }}},\n    \"aggs\": {\"avg_response\": {\"avg\": {\"field\": \"responsetime\"\
        }}}\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"
---
Test preview with non-existing source index:
- do:
    catch: "/.*Validation Failed.* no such index \\[does_not_exist\\]/"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": [\"airline-data\", \"does_not_exist\"]\
        \ },\n  \"pivot\": {\n    \"group_by\": {\n      \"airline\": {\"terms\":\
        \ {\"field\": \"airline\"}},\n      \"by-hour\": {\"date_histogram\": {\"\
        fixed_interval\": \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}}}\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"
---
Test preview returns bad request with invalid agg:
- do:
    catch: "bad_request"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"time\": {\"date_histogram\": {\"fixed_interval\"\
        : \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}},\n      \"time.min\": {\"min\"\
        : {\"field\": \"time\"}}\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"
- do:
    catch: "/field \\[time\\] cannot be both an object and a field/"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"time\": {\"date_histogram\": {\"fixed_interval\"\
        : \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}},\n      \"time.min\": {\"min\"\
        : {\"field\": \"time\"}}\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"
- do:
    catch: "/field \\[super_metric\\] cannot be both an object and a field/"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"time\": {\"date_histogram\": {\"fixed_interval\"\
        : \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\"\
        : {\"avg\": {\"field\": \"responsetime\"}},\n      \"super_metric.time\":\
        \ {\"min\": {\"field\": \"time\"}},\n      \"super_metric\": {\n        \"\
        scripted_metric\": {\n           \"init_script\": \"\",\n           \"map_script\"\
        : \"\",\n           \"combine_script\": \"\",\n           \"reduce_script\"\
        : \"return ['value1': 1, 'value2':2]\"\n        }\n      }\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"
---
Test preview with missing pipeline:
- do:
    catch: "bad_request"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"pipeline\"\
        : \"missing-pipeline\" },\n  \"pivot\": {\n    \"group_by\": {\n      \"time\"\
        : {\"date_histogram\": {\"fixed_interval\": \"1h\", \"field\": \"time\"}}},\n\
        \    \"aggs\": {\n      \"avg_response\": {\"avg\": {\"field\": \"responsetime\"\
        }},\n      \"time.min\": {\"min\": {\"field\": \"time\"}}\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"
---
Test preview with unsupported agg:
- do:
    catch: "bad_request"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"time\": {\"date_histogram\": {\"fixed_interval\"\
        : \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\n      \"vals\": {\"significant_terms\"\
        : {\"field\":\"airline\"}}\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"
- do:
    catch: "/Unsupported aggregation type \\[significant_terms\\]/"
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"pivot\": {\n \
        \   \"group_by\": {\n      \"time\": {\"date_histogram\": {\"fixed_interval\"\
        : \"1h\", \"field\": \"time\"}}},\n    \"aggs\": {\n      \"vals\": {\"significant_terms\"\
        : {\"field\":\"airline\"}}\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"
---
Test preview transform pivot with search runtime fields:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": {\n    \"index\": \"airline-data\",\n    \"runtime_mappings\"\
        \ : {\n      \"airline-upper\": {\n        \"type\": \"keyword\",\n      \
        \  \"script\": \"emit(doc['airline'].value.toUpperCase())\"\n      },\n  \
        \    \"responsetime_x_2\": {\n        \"type\": \"double\",\n        \"script\"\
        : \"emit(doc['responsetime'].value * 2.0)\"\n      },\n      \"time-5m\":\
        \ {\n        \"type\": \"date\",\n        \"script\": \"emit(doc['time'].value.toInstant().minus(5,\
        \ ChronoUnit.MINUTES).toEpochMilli())\"\n      }\n    }\n  },\n  \"pivot\"\
        : {\n    \"group_by\": {\n      \"airline\": {\"terms\": {\"field\": \"airline-upper\"\
        }},\n      \"by-hour\": {\"date_histogram\": {\"fixed_interval\": \"1h\",\
        \ \"field\": \"time\"}}},\n    \"aggs\": {\n      \"avg_response\": {\"avg\"\
        : {\"field\": \"responsetime_x_2\"}},\n      \"time.max\": {\"max\": {\"field\"\
        : \"time-5m\"}},\n      \"time.min\": {\"min\": {\"field\": \"time-5m\"}}\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"
- match:
    preview.0.airline: "FOO"
- match:
    preview.0.by-hour: "2017-02-18T00:00:00.000Z"
- match:
    preview.0.avg_response: 2.0
- match:
    preview.0.time.max: "2017-02-18T00:25:00.000Z"
- match:
    preview.0.time.min: "2017-02-17T23:55:00.000Z"
- match:
    preview.1.airline: "BAR"
- match:
    preview.1.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.1.avg_response: 84.0
- match:
    preview.1.time.max: "2017-02-18T00:55:00.000Z"
- match:
    preview.1.time.min: "2017-02-18T00:55:00.000Z"
- match:
    preview.2.airline: "FOO"
- match:
    preview.2.by-hour: "2017-02-18T01:00:00.000Z"
- match:
    preview.2.avg_response: 84.0
- match:
    preview.2.time.max: "2017-02-18T00:56:00.000Z"
- match:
    preview.2.time.min: "2017-02-18T00:56:00.000Z"
- match:
    generated_dest_index.mappings.properties.airline.type: "keyword"
- match:
    generated_dest_index.mappings.properties.by-hour.type: "date"
- match:
    generated_dest_index.mappings.properties.avg_response.type: "double"
- match:
    generated_dest_index.mappings.properties.time\.max.type: "date"
- match:
    generated_dest_index.mappings.properties.time\.min.type: "date"
---
Test preview transform latest with search runtime fields:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": {\n    \"index\": \"airline-data\",\n    \"runtime_mappings\"\
        \ : {\n      \"time-5m\": {\n        \"type\": \"date\",\n        \"script\"\
        : \"emit(doc['time'].value.toInstant().minus(5, ChronoUnit.MINUTES).toEpochMilli())\"\
        \n      }\n    }\n  },\n  \"latest\": {\n    \"unique_key\": [\"airline\"\
        ],\n    \"sort\": \"time-5m\"\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:
    $body: 2
- match:
    preview.0.airline: "bar"
- match:
    preview.0.time: "2017-02-18T01:00:00Z"
- is_false: "preview.0._isDeleted"
- is_false: "preview.0.time-5m"
- match:
    preview.1.airline: "foo"
- match:
    preview.1.time: "2017-02-18T01:01:00Z"
- is_false: "preview.1._isDeleted"
- is_false: "preview.1.time-5m"
---
Test preview continuous transform with no warnings:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": {\n    \"index\": \"airline-data\",\n    \"runtime_mappings\"\
        \ : {\n      \"time-10m\": {\n        \"type\": \"date\",\n        \"script\"\
        : \"emit(doc['time'].value.toInstant().minus(10, ChronoUnit.MINUTES).toEpochMilli())\"\
        \n      }\n    }\n  },\n  \"pivot\": {\n    \"group_by\": {\n      \"airline\"\
        : {\"terms\": {\"field\": \"airline\"}}\n    },\n    \"aggs\": {\n      \"\
        avg_response\": {\"avg\": {\"field\": \"responsetime\"}}\n    }\n  },\n  \"\
        sync\": {\n    \"time\": {\n      \"field\": \"time\"\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"
---
Test preview continuous transform with warnings:
- skip:
    features: "warnings"
- do:
    warnings:
    - "all the group-by fields are script-based runtime fields, this transform might\
      \ run slowly, please check your configuration."
    - "sync time field is a script-based runtime field, this transform might run slowly,\
      \ please check your configuration."
    transform.preview_transform:
      body: "{\n  \"source\": {\n    \"index\": \"airline-data\",\n    \"runtime_mappings\"\
        \ : {\n      \"airline-upper\": {\n        \"type\": \"keyword\",\n      \
        \  \"script\": \"emit(doc['airline'].value.toUpperCase())\"\n      },\n  \
        \    \"time-10m\": {\n        \"type\": \"date\",\n        \"script\": \"\
        emit(doc['time'].value.toInstant().minus(10, ChronoUnit.MINUTES).toEpochMilli())\"\
        \n      }\n    }\n  },\n  \"pivot\": {\n    \"group_by\": {\n      \"airline\"\
        : {\"terms\": {\"field\": \"airline-upper\"}}\n    },\n    \"aggs\": {\n \
        \     \"avg_response\": {\"avg\": {\"field\": \"responsetime\"}}\n    }\n\
        \  },\n  \"sync\": {\n    \"time\": {\n      \"field\": \"time-10m\"\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"
---
Test preview of unattended transform:
- do:
    transform.preview_transform:
      body: "{\n  \"source\": { \"index\": \"airline-data\" },\n  \"dest\": { \"index\"\
        : \"dest-airline-data-by-airline-unattended\" },\n  \"pivot\": {\n    \"group_by\"\
        : { \"airline\": {\"terms\": {\"field\": \"airline\"}}},\n    \"aggs\": {\"\
        avg_response\": {\"avg\": {\"field\": \"responsetime\"}}}\n  },\n  \"settings\"\
        : {\n    \"unattended\": 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"
---
Test preview transform latest with unique key field of aggregate_metric_double type:
- do:
    catch: "/Field \\[agg_metric\\] of type \\[aggregate_metric_double\\] is not supported\
      \ for aggregation \\[terms\\]/"
    transform.preview_transform:
      body: "{\n  \"source\": {\n    \"index\": \"airline-data\"\n  },\n  \"latest\"\
        : {\n    \"unique_key\": [\"agg_metric\"],\n    \"sort\": \"time\"\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"
