跳到主要内容
版本:v2.5.x

Compact()

This method compacts segments to improve search efficiency.

Go
func (c *Client) Compact(ctx context.Context, option CompactOption, callOptions ...grpc.CallOption) (int64, error)

notes

Milvus automatically compacts segments at intervals. Unless you have set a clustering key in your collection, you should rely on automatic compactions.

Request Parameters​

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

option

Optional parameters of the methods.

GetLoadStateOption

callOptions

Optional parameters for calling the methods.

grpc.CallOption

CompactOption​

This is an interface type. The compactOption struct type implements this interface type.

You can use the NewCompactOption() function to get the concrete implementation.

NewCompactOption()​

The signature of this method is as follows:

Go
func NewCompactOption(collectionName string) *compactOption

Parameter

Description

Type

collectionName

Name of the target collection.

string

Return​

int64 (A compaction ID)

Example​

Go
import (
"context"
"github.com/milvus-io/milvus/client/v2/milvusclient"
)

compactID, err := cli.Compact(ctx, milvusclient.NewCompactOption("customized_setup_1"))
if err != nil {
// handle err
}
fmt.Println(compactID)
// or GetCompactState ...