Delete objects
Overview
This page will show you how to delete objects in Weaviate by their id or a set of criteria.
Requirements
To delete a specific object, you'll need its id and class name.
To delete objects by a set of criteria, you'll need their class name, and a where
filter.
For classes where multi-tenancy is enabled, you will also need to specify the tenant name when deleting objects. See Manage data: multi-tenancy operations for details on how.
Why specify the class name?
Prior to Weaviate v1.14
it was possible to manipulate objects using only their ID without specifying the class name. This way is still supported for backward compatibility, but is considered deprecated now. Avoid using the deprecated endpoints, as they will be removed with Weaviate v2.0.0
.
The reason for the deprecation is that classes generally act like namespaces, therefore duplicate IDs are possible.
Additionally, where multi-tenancy (available from v1.20.0
) is enabled, the tenant name is required.
It is thus recommended to always include the class name when manipulating objects.
Delete object by id
To delete an object, specify its class name and id as shown below.
- Python
- JavaScript/TypeScript
- Java
- Go
uuid_to_delete = '...' # replace with the id of the object you want to delete
client.data_object.delete(
uuid=uuid_to_delete,
class_name='EphemeralObject', # Class of the object to be deleted
)
let idToDelete = '...'; // replace with the id of the object you want to delete
await client.data
.deleter()
.withClassName('EphemeralObject') // Class of the object to be deleted
.withId(idToDelete)
.do();
String idToDelete = "..."; // replace with the id of the object you want to delete
client.data().deleter()
.withClassName("EphemeralObject") // Class of the object to be deleted
.withID(idToDelete)
.run();
idToDelete := "..." // replace with the id of the object you want to delete
client.Data().Deleter().
WithClassName("EphemeralObject").
WithID(idToDelete).
Do(ctx)
You can also make a DELETE
request to the /v1/objects
endpoint directly.
Delete multiple objects
To delete multiple objects that match a set of criteria, specify the class and a where
filter.
Optionally, set output
to 'verbose'
to see more details (ID and deletion status).
- Python
- JavaScript/TypeScript
- Java
- Go
client.batch.delete_objects(
class_name='EphemeralObject',
where={
'path': ['name'],
'operator': 'Like',
'valueText': 'EphemeralObject*'
},
)
await client.batch
.objectsBatchDeleter()
.withClassName('EphemeralObject')
.withWhere({
path: ['name'],
operator: 'Like',
valueText: 'EphemeralObject*',
})
.do();
client.batch().objectsBatchDeleter()
.withClassName("EphemeralObject")
.withWhere(WhereFilter.builder()
.path("name")
.operator(Operator.Like)
.valueText("EphemeralObject*")
.build())
.run();
response, err := client.Batch().ObjectsBatchDeleter().
WithClassName("EphemeralObject").
WithOutput("minimal").
WithWhere(filters.Where().
WithPath([]string{"name"}).
WithOperator(filters.Like).
WithValueText("EphemeralObject*")).
Do(ctx)
if err != nil {
// handle error
panic(err)
}
fmt.Printf("%+v\n", *response)
You can also make DELETE
request to the /v1/batch/objects
endpoint directly.
There is a configurable maximum limit on the number of objects that can be deleted in a single query (default 10,000). To delete more objects than the limit, re-run the query.
ContainsAny / ContainsAll
You can use ContainsAny
/ ContainsAll
filters with the where
argument to delete objects that contains a specific value in a property.
Note that when using ContainsAny
or ContainsAll
, the query must be entered as an array of values. The client-specific syntax varies as follows:
- Python
- JavaScript/TypeScript
- Java
- Go
client.batch.delete_objects(
class_name='EphemeralObject',
where={
'path': ['name'],
'operator': 'ContainsAny',
'valueTextArray': ['asia', 'europe'] # Note the array syntax
},
)
await client.batch
.objectsBatchDeleter()
.withClassName('EphemeralObject')
.withWhere({
path: ['name'],
operator: 'ContainsAny',
valueTextArray: ['asia', 'europe'], // Note the array syntax
})
.do();
client.batch().objectsBatchDeleter()
.withClassName("EphemeralObject")
.withWhere(WhereFilter.builder()
.path("name")
.operator(Operator.ContainsAny)
.valueText("asia", "europe") // Note the array syntax
.build())
.run();
response, err := client.Batch().ObjectsBatchDeleter().
WithClassName("EphemeralObject").
WithOutput("minimal").
WithWhere(filters.Where().
WithPath([]string{"name"}).
WithOperator(filters.ContainsAny).
WithValueText("asia", "europe")). // Note the array syntax
Do(ctx)
Dry-run
You can set the dryRun
option to check how many objects would be deleted, without actually performing the deletion.
- Python
- JavaScript/TypeScript
- Java
- Go
result = (
client.batch.delete_objects(
class_name='EphemeralObject',
# Same `where` filter as in the GraphQL API
where={
'path': ['name'],
'operator': 'Like',
'valueText': 'EphemeralObject*'
},
dry_run=True,
output='verbose'
)
)
import json
print(json.dumps(result, indent=2))
let response = await client.batch
.objectsBatchDeleter()
.withClassName('EphemeralObject')
// Same `where` filter as in the GraphQL API
.withWhere({
path: ['name'],
operator: 'Like',
valueText: 'EphemeralObject*',
})
.withDryRun(true)
.withOutput('verbose')
.do();
console.log(response);
client.batch().objectsBatchDeleter()
.withClassName("EphemeralObject")
// Same `where` filter as in the GraphQL API
.withWhere(WhereFilter.builder()
.path("name")
.operator(Operator.Like)
.valueText("EphemeralObject*")
.build())
.withDryRun(true)
.withOutput(BatchDeleteOutput.VERBOSE)
.run();
response, err := client.Batch().ObjectsBatchDeleter().
WithClassName("EphemeralObject").
// Same `where` filter as in the GraphQL API
WithWhere(filters.Where().
WithPath([]string{"name"}).
WithOperator(filters.Like).
WithValueText("EphemeralObject*")).
WithDryRun(true).
WithOutput("verbose").
Do(ctx)
if err != nil {
// handle error
panic(err)
}
fmt.Printf("%+v\n", *response)
Example response
It should produce a response like the one below:
{
"dryRun": true,
"match": {
"class": "EphemeralObject",
"where": {
"operands": null,
"operator": "Like",
"path": [
"name"
],
"valueText": "EphemeralObject*"
}
},
"output": "verbose",
"results": {
"failed": 0,
"limit": 10000,
"matches": 5,
"objects": [
{
"id": "208cf21f-f824-40f1-95cb-f923bc840ca6",
"status": "DRYRUN"
},
{
"id": "8b2dddd4-2dc7-422c-885d-f9d5ff4e80c8",
"status": "DRYRUN"
},
{
"id": "49b3b2b4-3a77-48cd-8e39-27e83c811fcc",
"status": "DRYRUN"
},
{
"id": "847b31d0-dab4-4c1c-8cd3-af07c9d3dc2c",
"status": "DRYRUN"
},
{
"id": "147d9cea-5f9c-40c1-884a-f99bc8e9bf06",
"status": "DRYRUN"
}
],
"successful": 0
}
}
More Resources
For additional information, try these sources.