Delete
This operation deletes entities from a collection by primary key values or filter expression.
func (c *Client) Delete(ctx context.Context, option DeleteOption, callOptions ...grpc.CallOption) (DeleteResult, error)
Request Syntax
Creates the request for Delete().
option := milvusclient.NewDeleteOption(collectionName).
WithExpr(expr).
WithInt64IDs(fieldName, ids).
WithStringIDs(fieldName, ids).
WithPartition(partitionName)
result, err := client.Delete(ctx, option)
PARAMETERS:
-
collectionName (string) -
[REQUIRED]
The name of the target collection.
BUILDER METHODS:
-
NewDeleteOption(collectionName string)Creates the request for Delete().
-
WithExpr(expr string)Sets the expr for the operation.
-
WithTemplateParam(key string, val any)Sets a template parameter for expression evaluation.
-
WithInt64IDs(fieldName string, ids []int64)Sets the int64 IDs for the operation.
-
WithStringIDs(fieldName string, ids []string)Sets the string IDs for the operation.
-
WithPartition(partitionName string)Sets the partition for the operation.
-
WithNamespace(namespace string)Scopes the delete to a collection namespace.
RETURN TYPE:
DeleteResult, error
RETURNS:
The delete result. Returns an error if the operation fails.
type DeleteResult struct {
DeleteCount int64
}
PARAMETERS:
-
DeleteCount (int64) -
The number of affected entities.
ERROR HANDLING:
-
error
The operation fails. Check
err != nilfor failure details.
Example
Demonstrates Delete() usage.
import (
"context"
"fmt"
"github.com/milvus-io/milvus/client/v3/milvusclient"
)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cli, err := milvusclient.New(ctx, &milvusclient.ClientConfig{
Address: milvusAddr,
})
if err != nil {
// handle error
}
defer cli.Close(ctx)
res, err := cli.Delete(ctx, milvusclient.NewDeleteOption("quick_setup").
WithInt64IDs("id", []int64{1, 2, 3}))
if err != nil {
// handle error
}
fmt.Println(res.DeleteCount)