Skip to main content

Get()

This method gets entities by their IDs.

func (c *GrpcClient) Get(ctx context.Context, collectionName string, ids entity.Column, opts ...GetOption) (ResultSet, error)

Parameter

Description

Type

ctx

Context for the current call to work.

context.Context

collectionName

Name of a collection.

string

ids

Boolean expression for metadata filtering.

For details, refer to Scalar Filtering Rules.

entity.Column

opts

Extra query options.

You can add multiple client.GetOption instances.

...client.GetOption

client.GetOption

You can add extra settings to the Get() request using the following methods.

Method

Description

GetWithOutputFields(outputFields ...string)

Sets the names of fields to be included in the return.

GetWithPartitions(partitionNames ...string)

Restricts the query within the specified partitions.

A client.ResultSet, which is a slice of entity.Column.

client.ResultSet

The client.ResultSet provides the following methods for you to manipulate the query results.

Method

Return Type

Description

GetColumn(fieldName string)

entity.Column

Return the column with the provided name.

Len()

int

Return the number of entities in the query result.

Slice(start, end int)

client.ResultSet

Return a slice of the query result.

Errors

Any error in the execution of the request. Possible errors are as follows:

  • ErrClientNotReady: The client is not connected to Milvus.

  • ErrCollectionNotExists: The collection with the specified name does not exist.

  • The call to this API fails.

Example

// get
ids := entity.NewColumnInt64("id", []int64{10, 11, 12, 19})
queryRes, errQuery := mc.Get(context.Background(), collectionName, ids, client.GetWithOutputFields("varchar"))
if errQuery != nil {
log.Fatal("failed to query collection:", errQuery.Error())
}
for _, res := range queryRes {
log.Println(res.Name(), res.FieldData())
}