Skip to main content
Weaviate Docs (migrated from docs.weaviate.io) Docs

Search documentation

Type to search this documentation.

On this pageOverview

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.

To delete by id, specify the collection name and the object id.

Python
uuid_to_delete = "..."  # replace with the id of the object you want to delete
JavaScript/TypeScript
await client.collections.delete('EphemeralObject')
await client.collections.create({ name: 'EphemeralObject'})
const myCollection = client.collections.use('EphemeralObject')
Go
idToDelete := "..." // replace with the id of the object you want to delete
Java
collection.data.deleteById(uuidToDelete);
C#
await collection.Data.DeleteByID(uuidToDelete);

To delete objects that match a set of criteria, specify the collection and a where filter.

Python
from weaviate.classes.query import Filtercollection = client.collections.use("EphemeralObject")collection.data.delete_many(    where=Filter.by_property("name").like("EphemeralObject*"))
JavaScript/TypeScript
await client.collections.delete('EphemeralObject')
await client.collections.create({ name: 'EphemeralObject'})
const myCollection = client.collections.use('EphemeralObject')
Go
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)
Java
collection.data.deleteMany(    Filter.property("name").like("EphemeralObject*"));
C#
await collection.Data.DeleteMany(    Filter.Property("name").IsLike("EphemeralObject*"));
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 / ContainsNone filters to delete of objects by a set of criteria.

Python
from weaviate.classes.query import Filtercollection = client.collections.use("EphemeralObject")collection.data.delete_many(    where=Filter.by_property("name").contains_any(["europe", "asia"]))
JavaScript/TypeScript
await client.collections.delete('EphemeralObject')
await client.collections.create({ name: 'EphemeralObject'})
const myCollection = client.collections.use('EphemeralObject')
Go
  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)
Java
CollectionHandle<Map<String, Object>> collection =    client.collections.use(COLLECTION_NAME);collection.data.insertMany(Map.of("name", "asia"),    Map.of("name", "europe"));collection.data.deleteMany(    Filter.property("name").containsAny("europe", "asia"));
C#
var collection = client.Collections.Use(COLLECTION_NAME);await collection.Data.InsertMany(new[] { new { name = "asia" }, new { name = "europe" } });await collection.Data.DeleteMany(    Filter.Property("name").ContainsAny(["europe", "asia"]));

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
from weaviate.classes.query import Filtercollection = client.collections.use("EphemeralObject")response = collection.query.fetch_objects(limit=3)  # Fetch 3 object IDsids = [o.uuid for o in response.objects]  # These can be lists of strings, or `UUID` objectscollection.data.delete_many(    where=Filter.by_id().contains_any(ids)  # Delete the 3 objects)
JavaScript/TypeScript
await client.collections.delete('EphemeralObject')
await client.collections.create({ name: 'EphemeralObject'})
const myCollection = client.collections.use('EphemeralObject')
Go
  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)
Java
QueryResponse<Map<String, Object>> queryResponse =    collection.query.fetchObjects(q -> q.limit(3));List<String> ids = queryResponse.objects()    .stream()    .map(WeaviateObject::uuid)    .collect(Collectors.toList());collection.data.deleteMany(    Filter.uuid().containsAny(ids.toArray(new String[0])) // Delete the 3 objects);
C#
var queryResponse = await collection.Query.FetchObjects(limit: 3);var ids = queryResponse.Objects.Select(obj => obj.UUID.Value).ToList();await collection.Data.DeleteMany(    Filter.UUID.ContainsAny(ids) // Delete the 3 objects);

Objects must belong to a collection in Weaviate. Accordingly deleting collections will remove all objects within them.

You can configure automatic deletion of objects after a specified time period using Time-To-Live (TTL) settings at the collection level. Read how to set it up or learn more about it.

  • 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
from weaviate.classes.query import Filtercollection = client.collections.use("EphemeralObject")result = collection.data.delete_many(    where=Filter.by_property("name").like("EphemeralObject*"),    dry_run=True,    verbose=True)print(result)
JavaScript/TypeScript
await client.collections.delete('EphemeralObject')
await client.collections.create({ name: 'EphemeralObject'})
const myCollection = client.collections.use('EphemeralObject')
Go
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)
Java
var result = collection.data.deleteMany(    Filter.property("name").like("EphemeralObject*"),    c -> c.dryRun(true).verbose(true));System.out.println(result);
C#
var result = await collection.Data.DeleteMany(    Filter.Property("name").IsLike("EphemeralObject*"),    dryRun: true);Console.WriteLine(JsonSerializer.Serialize(result));
Example response

It should produce a response like the one below:

JSON
{
  "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
  }
}

Have a question or feedback? Here's how to reach us.

Suggest an edit

Propose a replacement for this page. The site team reviews it before applying any changes.

Export
Documentation menu