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]";
private static final String DELETE_EXPR = "book_id in [0,1]";
pks := entity.NewColumnInt64("book_id", []int64{0, 1})
var expression = "book_id in [0,1]";
# See the following section.
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.deleteEntities({
collection_name: "book",
expr: expr,
});
client.DeleteByPks("book", pks)
milvusClient.delete(
DeleteParam.newBuilder()
.withCollectionName("book")
.withExpr(DELETE_EXPR)
.build()
);
await milvusClient.GetCollection("book").DeleteAsync(expression);
curl -X 'POST' \
'${MILVUS_HOST}:${MILVUS_PORT}/v1/vector/delete' \
-H 'Authorization: Bearer ${TOKEN}' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"collectionName": "collection1",
"id": 1
}'
Output:
{
"code": 200,
"data": {}
}
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. |
Parameter | Description |
---|---|
collName |
Name of the collection to delete entities from. |
partitionName (optional) |
Name of the partition to delete entities from. |
ids |
A set of ids to delete. |
Parameter | Description |
---|---|
CollectionName |
Name of the collection to delete entities from. You should get a collection and call its InsertAsync with the following parameters. |
expression |
Boolean expression that specifies the entities to delete. |
PartitionName (optional) |
Name of the partition to delete entities from. |
Parameter | Description |
---|---|
collectionName |
The name of the collection to which this operation applies. |
id |
The ID of the entity to drop. |
What’s next
- Learn more basic operations of Milvus: