Delete objects
Weaviate allows object deletion by id or by a set of criteria.
Additional information
To delete objects, you must provide the collection name as well as identifying criteria (e.g. object id or filters).
For multi-tenancy collections, you will also need to specify the tenant name when deleting objects. See Manage data: multi-tenancy operations for details on how.
Collection (class) Name in Object CRUD OperationsCollections act like namespaces, so two different collections could have duplicate IDs between them.
Prior to Weaviate
v1.14
you can manipulate objects without specifying the collection name. This method is deprecated. It will be removed in Weaviatev2.0.0
.Starting in
v1.20
, you can have multi-tenant datasets. Whenmulti-tenancy
is enabled, the tenant name is required.Always include the collection name, and, when enabled, the tenant name.
Delete object by id
To delete by id, specify the collection name and the object id.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
uuid_to_delete = "..." # replace with the id of the object you want to delete
collection = client.collections.get("EphemeralObject")
collection.data.delete_by_id(
uuid_to_delete
)
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
)
const myCollection = client.collections.get('EphemeralObject')
let idToDelete = '...'; // replace with the id of the object you want to delete
await myCollection.data.deleteById(idToDelete)
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)
Delete multiple objects
To delete objects that match a set of criteria, specify the collection and a where
filter.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.query import Filter
collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=Filter.by_property("name").like("EphemeralObject*")
)
client.batch.delete_objects(
class_name="EphemeralObject",
where={
"path": ["name"],
"operator": "Like",
"valueText": "EphemeralObject*"
},
)
const myCollection = client.collections.get('EphemeralObject')
const response = await myCollection.data.deleteMany(
myCollection.filter.byProperty('name').like('EphemeralObject*')
)
console.log(JSON.stringify(response))
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)
Additional information
- There is a configurable maximum limit (QUERY_MAXIMUM_RESULTS) 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.
Use ContainsAny / ContainsAll
The ContainsAny
/ ContainsAll
filters allow deletion of objects that match a set of criteria.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.query import Filter
collection = client.collections.get("EphemeralObject")
collection.data.delete_many(
where=Filter.by_property("name").contains_any(["europe", "asia"])
)
client.batch.delete_objects(
class_name="EphemeralObject",
where={
"path": ["name"],
"operator": "ContainsAny",
"valueTextArray": ["asia", "europe"] # Note the array syntax
},
)
const myCollection = client.collections.get('EphemeralObject')
await myCollection.data.deleteMany(
myCollection.filter.byProperty('name').containsAny(['europe', 'asia'])
)
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)
Additional information
This feature was added in Weaviate v1.21
.
Delete multiple objects by id
To delete multiple objects by their id values, use a filter (e.g. ContainsAny
) with id
based criteria.
Limitations
There is an upper limit (QUERY_MAXIMUM_RESULTS
) to how many objects can be deleted using a single query. This protects against unexpected memory surges and very-long-running requests which would be prone to client-side timeouts or network interruptions.
Objects are deleted in the same order that they would be fetched, by order of UUID. To delete more objects than the limit, run the same query multiple times until no objects are matched anymore.
The default QUERY_MAXIMUM_RESULTS
value is 10,000. This may be configurable, e.g. in the environment variables.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.query import Filter
collection = client.collections.get("EphemeralObject")
response = collection.query.fetch_objects(limit=3) # Fetch 3 object IDs
ids = [o.uuid for o in response.objects] # These can be lists of strings, or `UUID` objects
collection.data.delete_many(
where=Filter.by_id().contains_any(ids) # Delete the 3 objects
)
client.batch.delete_objects(
class_name="EphemeralObject",
where={
"path": ["id"],
"operator": "ContainsAny",
"valueTextArray": ["12c88739-7a4e-49fd-bf53-d6a829ba0261", "3022b8be-a6dd-4ef4-b213-821f65cee53b", "30de68c1-dd53-4bed-86ea-915f34faea63"] # Note the array syntax
},
)
const myCollection = client.collections.get('EphemeralObject')
const response = await myCollection.query.fetchObjects({limit: 3})
const idList = response.objects.map(o => o.uuid)
await myCollection.data.deleteMany(
myCollection.filter.byId().containsAny(idList)
)
await client.batch
.objectsBatchDeleter()
.withClassName('EphemeralObject')
.withWhere({
path: ['id'],
operator: 'ContainsAny',
valueTextArray: ['12c88739-7a4e-49fd-bf53-d6a829ba0261', '3022b8be-a6dd-4ef4-b213-821f65cee53b', '30de68c1-dd53-4bed-86ea-915f34faea63'], // Note the array syntax
})
.do();
client.batch().objectsBatchDeleter()
.withClassName("EphemeralObject")
.withWhere(WhereFilter.builder()
.path("id")
.operator(Operator.ContainsAny)
.valueText("12c88739-7a4e-49fd-bf53-d6a829ba0261", "3022b8be-a6dd-4ef4-b213-821f65cee53b", "30de68c1-dd53-4bed-86ea-915f34faea63") // Note the array syntax
.build())
.run();
response, err := client.Batch().ObjectsBatchDeleter().
WithClassName("EphemeralObject").
WithOutput("minimal").
WithWhere(filters.Where().
WithPath([]string{"id"}).
WithOperator(filters.ContainsAny).
WithValueText("12c88739-7a4e-49fd-bf53-d6a829ba0261", "3022b8be-a6dd-4ef4-b213-821f65cee53b", "30de68c1-dd53-4bed-86ea-915f34faea63")). // Note the array syntax
Do(ctx)
Optional parameters
- You can use
dryRun
to check how many objects would be deleted, without actually performing the deletion. - Set
output
to'verbose'
to see more details (ID and deletion status) for each deletion.
- Python Client v4
- Python Client v3
- JS/TS Client v3
- JS/TS Client v2
- Java
- Go
from weaviate.classes.query import Filter
collection = client.collections.get("EphemeralObject")
result = collection.data.delete_many(
where=Filter.by_property("name").like("EphemeralObject*"),
dry_run=True,
verbose=True
)
print(result)
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))
const myCollection = client.collections.get('EphemeralObject')
const response = await myCollection.data.deleteMany(
myCollection.filter.byProperty('name').like('EphemeralObject'),
{
dryRun: true,
verbose: true
}
)
console.log(response);
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
}
}
Related pages
Questions and feedback
If you have any questions or feedback, let us know in the user forum.