CreateIndex()
This method creates an index for a specific field in a collection.
func (c *GrpcClient) CreateIndex(ctx context.Context, collName string, fieldName string, idx entity.Index, async bool, opts ...IndexOption) error
Parameter | Description | Type |
---|---|---|
| Context for the current call to work. |
|
| Name of a collection |
|
| Name of the field to index. |
|
| Index settings. |
|
| Whether this operation is asynchronous. |
|
| Extra index settings You can include multiple |
|
entity.Index
This interface type defines a set of method signatures as follows.
type Index interface {
Name() string
IndexType() IndexType
Params() map[string]string
}
Method Signature | Return Type | Description |
---|---|---|
|
| Return the index name. |
|
| Return the index type. |
|
| Return the index parameters. |
For details on the struct types that implement the above method signatures and applicable index types, refer to Indexes.
client.IndexOption
This type provides methods to modify index settings when you create, describe, or drop indexes. The following methods return client.IndexOption
.
Method | Description |
---|---|
| Name of the index to create. The value defaults to the target field name. |
| Whether to enable MMap for the index. |
Return
Null
Errors
Any error in the execution of the request. Possible errors are as follows:
-
ErrClientNotReady
: The client is not connected to Milvus. -
A field with the same name does not exist.
-
The call to this API fails.
Example
// create index
idxHnsw, errIdx := entity.NewIndexHNSW(entity.COSINE, 8, 200)
if errIdx != nil {
log.Fatal("failed to new index:", errIdx.Error())
}
errIndex := mc.CreateIndex(context.Background(), collectionName, "vector", idxHnsw, false, client.WithIndexName("myIdx"))
if errIndex != nil {
log.Fatal("failed to create index:", errIndex.Error())
}