ElasticSearch delete model with force does not work

According to the documentation here
https://www.elastic.co/guide/en/elasticsearch/reference/8.6/delete-trained-models.html#ml-delete-trained-models-query-parms it is possible to use the parameter "force" to force the deletion of a model.

However, when I try to delete the model using the API I get the following error:

{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "request [DELETE /_ml/trained_models/neuralmind__bert-base-portuguese-cased] does not support having a body"
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "request [DELETE /_ml/trained_models/neuralmind__bert-base-portuguese-cased] does not support having a body"
  },
  "status": 400
}

Supposedly it is possible to have a body in the request, however it is not allowed to use the force parameter because having a body for a DELETE is not supported.

This is the code I used to delete the model:

tm = eland.ml.pytorch.transformers.TransformerModel(model_name, task_type)

model_id = tm.elasticsearch_model_id()
print("Model id: ",model_id)
es_model = eland.ml.MLModel(
    es_client=es,#"http://localhost:9200",
    #http_auth=(ROOT_USER, ROOT_USER_PASSWORD),
    model_id= model_id
)
model_exists = es_model.exists_model()
print("Model exists:" , model_exists)
#delete models
#https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-trained-models.html
if(model_exists):
    #stop the model with force is allowed
    url = ENDPOINT_ELASTIC+"/_ml/trained_models/"+model_id+"/deployment/_stop"
    payload= {"force":True}
    response = requests.request("POST", url, headers=headers, data=json.dumps(payload))
    print(json.dumps(json.loads(response.text), indent = 2))
    
    #delete the model
    payload= {"force":True}
    url = ENDPOINT_ELASTIC+"/_ml/trained_models/"+model_id
    response = requests.request("DELETE", url, headers=headers, data=json.dumps(payload))
    print(json.dumps(json.loads(response.text), indent = 2))

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.