Delete synonyms set
Deletes a synonyms set.
Request
DELETE _synonyms/<synonyms_set>
Prerequisites
- Requires the
manage_search_synonymscluster privilege. - You can only delete a synonyms set that is not in use by any index analyzer. See Delete synonyms set analyzer requirements for more information.
Path parameters
-
<synonyms_set> - (Required, string) Synonyms set identifier to delete.
Response codes
-
400 - The
synonyms_setidentifier was not provided, or the synonyms set can’t be deleted because it does not meet the specified requirements. -
404(Missing resources) - No synonyms set with the identifier
synonyms_setwas found.
Examples
The following example deletes a synonyms set called my-synonyms-set:
resp = client.synonyms.delete_synonym(
id="my-synonyms-set",
)
print(resp) response = client.synonyms.delete_synonym( id: 'my-synonyms-set' ) puts response
const response = await client.synonyms.deleteSynonym({
id: "my-synonyms-set",
});
console.log(response); DELETE _synonyms/my-synonyms-set
Delete synonyms set analyzer requirements
synonyms sets can be used in synonym graph token filters and synonym token filters. These synonym filters can be used as part of search analyzers.
Analyzers need to be loaded when an index is restored (such as when a node starts, or the index becomes open). Even if the analyzer is not used on any field mapping, it still needs to be loaded on the index recovery phase.
If any analyzers cannot be loaded, the index becomes unavailable and the cluster status becomes red or yellow as index shards are not available.
To prevent that, synonyms sets that are used in analyzers can’t be deleted. A delete request in this case will return a 400 response code with the following error message:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "synonyms set [my-synonyms-set] cannot be deleted as it is used in the following indices: index-1, index-2",
"stack_trace": ...
}
],
"type": "illegal_argument_exception",
"reason": "synonyms set [my-synonyms-set] cannot be deleted as it is used in the following indices: index-1, index-2",
"stack_trace": ...
},
"status": 400
} To remove a synonyms set, you must first remove all indices that contain analyzers using it. You can migrate an index by creating a new index that does not contain the token filter with the synonyms set, and use the Reindex in order to copy over the index data. Once finished, you can delete the index.
When the synonyms set is not used in analyzers, you will be able to delete it.
© 2023-2025 Elasticsearch
As of September 2024, Elasticsearch is available under a choice of three licenses: the Server Side Public License (SSPL), the Elastic License, or the AGPLv3 (OSI approved).
Elasticsearch and the Elasticsearch logo are trademarks of Elasticsearch B.V., registered in the U.S. and in other countries.
https://www.elastic.co/guide/en/elasticsearch/reference/8.17/delete-synonyms-set.html