milvus-logo

Delete Entities

This topic describes how to delete entities in Milvus.

Milvus supports deleting entities by primary key filtered with boolean expression.

  • Deleted entities can still be retrieved immediately after the deletion if the consistency level is set lower than Strong.
  • Entities deleted beyond the pre-specified span of time for Time Travel cannot be retrieved again.
  • Frequent deletion operations will impact the system performance.

Prepare boolean expression

Prepare the boolean expression that filters the entities to delete.

Milvus only supports deleting entities with clearly specified primary keys, which can be achieved merely with the term expression in. Other operators can be used only in query or scalar filtering in vector search. See Boolean Expression Rules for more information.

The following example filters data with primary key values of 0 and 1.

expr = "book_id in [0,1]"
const expr = "book_id in [0,1]";
// This function is under active development on the GO client.
private static final String DELETE_EXPR = "book_id in [0,1]";
delete entities -c book
The expression to specify entities to be deleted: book_id in [0,1]
Option Description
-c The name of the collection.
-p (Optional) The name of the partition that the entities belong to.

Delete entities

Delete the entities with the boolean expression you created. Milvus returns the ID list of the deleted entities.

from pymilvus import Collection
collection = Collection("book")      # Get an existing collection.
collection.delete(expr)
await milvusClient.dataManager.deleteEntities({
  collection_name: "book",
  expr: expr,
});
// This function is under active development on the GO client.
milvusClient.delete(
  DeleteParam.newBuilder()
    .withCollectionName("book")
    .withExpr(DELETE_EXPR)
    .build()
);
You are trying to delete the entities of collection. This action cannot be undone!
Do you want to continue? [y/N]: y
Parameter Description
expr Boolean expression that specifies the entities to delete.
partition_name (optional) Name of the partition to delete entities from.
Parameter Description
collection_name Name of the collection to delete entities from.
expr Boolean expression that specifies the entities to delete.
partition_name (optional) Name of the partition to delete entities from.
Parameter Description
CollectionName Name of the collection to delete entities from.
expr Boolean expression that specifies the entities to delete.
PartitionName (optional) Name of the partition to delete entities from.

What's next

On this page