跳到主要内容

get()

The MilvusClient interface. This method gets entity(s) based on the primary field ids. Note that the order of the returned entities can not be guaranteed.

R<GetResponse> get(GetIdsParam requestParam);

GetIdsParam

Use the GetIdsParam.Builder to construct a GetIdsParam object.

import io.milvus.param.highlevel.dml.GetIdsParam;
GetIdsParam.Builder builder = GetIdsParam.newBuilder();

Methods of GetIdsParam.Builder:

Method

Description

Parameters

withCollectionName(String collectionName)

Sets the target collection name. Collection name cannot be empty or null.

collectionName: The name of the collection to insert data into.

withPrimaryIds(List<T> primaryIds)

Specifies id fields. ID cannot be empty or null.
Note only support the value of primary key.

primaryIds: a list of primary field key objects.

addPrimaryId(T primaryId)

Specifies primaryField id. PrimaryId cannot be empty or null.
Note only support the value of primary key.

primaryId: The id of primary field key.

withOutputFields(List<String> outputFields)

Specifies output fields (Optional).

outputFields: A list of output field you need.

withConsistencyLevel(ConsistencyLevelEnum consistencyLevel)

Consistency level used in the get. If no level is specified, will use default consistency. Please refer to ConsistencyLevelEnum in Misc.

consistencyLevel: The consistency level used in the get.

build()

Constructs an GetIdsParam object.

N/A

The GetIdsParam.Builder.build() can throw the following exceptions:

  • ParamException: error if the parameter is invalid.

Returns

This method catches all the exceptions and returns an R<GetResponse> object.

  • If the API fails on the server side, it returns the error code and message from the server.

  • If the API fails by RPC exception, it returns R.Status.Unknown and the error message of the exception.

  • If the API succeeds, it returns a valid GetResponse held by the R template.

Example

import io.milvus.param.*;
import io.milvus.response.QueryResultsWrapper;
import io.milvus.response.FieldDataWrapper;
import io.milvus.grpc.QueryResults;

List<String> ids = Lists.newArrayList("441966745769900131", "441966745769900133");
GetIdsParam getParam = GetIdsParam.newBuilder()
.withCollectionName(COLLECTION_NAME)
.withId(ids)
.withOutputFields(Lists.newArrayList("*"))
.build();

R<GetResponse> response = client.get(param)
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}

for (QueryResultsWrapper.RowRecord rowRecord : response.getData().getRowRecords()) {
System.out.println(rowRecord);
}