elasticsearch
elasticsearch copied to clipboard
Issue-105420: Fix bug causing incorrect error on force deleting already deleted model
What I did:
Previously, attempting to force delete a referenced model in Elasticsearch that had already been deleted would result in an error indicating that the model is still being referenced by ingest processors. This behavior was misleading since the model no longer exists in the system.
Changes made:
- Modified the
deleteModel
method to to properly check for the existence of the model before proceeding with the deletion process.
With this fix, attempting to force delete an already deleted model will now correctly indicate that the model isn't found, rather than misleadingly reporting it as still being referenced.
Related issue:
Fixes https://github.com/elastic/elasticsearch/issues/105420
How did I test my fix:
I built and started up elasticsearch locally, then I downloaded a new model using the following command:
curl --insecure -u "elastic:<password>" -X PUT "https://localhost:9200/_ml/trained_models/.elser_model_2?pretty" -H 'Content-Type: application/json' -d' { "input": { "field_names": ["text_field"] } } '
Then I attempted to delete it and it said that it's being referenced as expected:
curl --insecure -u "elastic:<password>" -X DELETE "https://localhost:9200/_ml/trained_models/.elser_model_2?pretty" { "error" : { "root_cause" : [ { "type" : "status_exception", "reason" : "Cannot delete model [.elser_model_2] as it is still referenced by ingest processors; use force to delete the model" } ], "type" : "status_exception", "reason" : "Cannot delete model [.elser_model_2] as it is still referenced by ingest processors; use force to delete the model" }, "status" : 409 }
I force deleted it the first time:
curl --insecure -u "elastic:<password>" -X DELETE "https://localhost:9200/_ml/trained_models/.elser_model_2?force=true" {"acknowledged":true}%
It now returns the right error response when I attempt to delete the same model again:
curl --insecure -u "elastic:<password>" -X DELETE "https://localhost:9200/_ml/trained_models/.elser_model_2" {"error":{"root_cause":[{"type":"resource_not_found_exception","reason":"Could not find trained model [.elser_model_2]"}],"type":"resource_not_found_exception","reason":"Could not find trained model [.elser_model_2]"},"status":404}%
PR checklist:
-
Have you signed the contributor license agreement? :heavy_check_mark:Yes
-
Have you followed the contributor guidelines? :heavy_check_mark:Yes
-
If submitting code, have you built your formula locally prior to submission with
gradle check
?I ran tests in the package to make sure I didn't break anything, here's the command I ran:
./gradlew :x-pack:plugin:ml:test
Here's a screenshot showing that the tests succeeded:
- If submitting code, is your pull request against main? Unless there is a good reason otherwise, we prefer pull requests against main and will backport as needed. :heavy_check_mark:Yes
- If submitting code, have you checked that your submission is for an OS and architecture that we support? :heavy_check_mark:Yes
- If you are submitting this code for a class then read our policy for that. N/A
Pinging @elastic/ml-core (Team:ML)
@elasticmachine test this please