setup:
  - skip:
      features: headers
  - do:
      headers:
        Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
      indices.create:
        index: store
        body:
          mappings:
            properties:
              product:
                type: keyword
              cost:
                type: integer
              time:
                type: date

---
"Test setting results field is invalid":

  - do:
      catch: /action_request_validation_exception/
      search:
        index: store
        body: |
          {
            "size": 0,
            "query": { "match_all" : { } },
            "aggs": {
              "good": {
                "terms": {
                  "field": "product",
                  "size": 10
                },
                "aggs": {
                  "avg_cost_agg": {
                    "avg": {
                      "field": "cost"
                    }
                  },
                  "regression_agg" : {
                    "inference": {
                      "model_id": "a-complex-regression-model",
                      "inference_config": {
                        "regression": {
                          "results_field": "banana"
                        }
                      },
                      "buckets_path": {
                        "cost" : "avg_cost_agg"
                      }
                    }
                  }
                }
              }
            }
          }
  - match: { error.root_cause.0.type: "action_request_validation_exception" }
  - match: { error.root_cause.0.reason: "Validation Failed: 1: setting option [results_field] to [banana] is not valid for inference aggregations;" }
