# ElasticSearch delete model with force does not work

**URL:** <https://discuss.elastic.co/t/elasticsearch-delete-model-with-force-does-not-work/329781>\
**Category:** Elasticsearch\
**Created:** [April 11, 2023, 10:23pm UTC](https://discuss.elastic.co/t/elasticsearch-delete-model-with-force-does-not-work/329781 "2023-04-11T22:23:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diogo\_Moura](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/diogo_moura/32/119711_2.png) [@Diogo\_Moura](https://discuss.elastic.co/u/Diogo_Moura)\
**Post date:** [April 11, 2023, 10:23pm UTC](https://discuss.elastic.co/t/elasticsearch-delete-model-with-force-does-not-work/329781/1 "2023-04-11T22:23:17Z")

</div>

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](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:

```auto
{
  "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:

```auto
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))

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 9, 2023, 10:23pm UTC](https://discuss.elastic.co/t/elasticsearch-delete-model-with-force-does-not-work/329781/2 "2023-05-09T22:23:30Z")

</div>

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