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

getAsync()

Gets specific entities by their IDs asynchronously and returns a future.

Java
public CompletableFuture<GetResp> getAsync(GetReq request)

This method uses the same request parameters as get() but returns a CompletableFuture<GetResp> immediately. Use the returned future to consume the result or handle the exceptional completion when the operation fails.

Request Syntax​

Java
CompletableFuture<GetResp> future = client.getAsync(GetReq.builder()
.collectionName(String collectionName)
.ids(List<Object> ids)
.build());

For the full list of GetReq builder methods, refer to get().

RETURN TYPE:

CompletableFuture<GetResp>

RETURNS:

A future completed with a GetResp, or completed exceptionally when the operation fails. The GetResp object exposes the following getters:

  • getGetResults() (List<QueryResp.QueryResult>) -

    The queried entities. Each QueryResult has the following getters:

    • getEntity() (Map<String, Object>) -

      The field values of the result.

EXCEPTIONS:

  • MilvusClientException

    This exception will be raised when request validation, transport, or server execution fails.

Example​

Java
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.GetReq;
import io.milvus.v2.service.vector.response.GetResp;

import java.util.Collections;
import java.util.concurrent.CompletableFuture;

ConnectConfig connectConfig = ConnectConfig.builder()
.uri("http://localhost:19530")
.token("root:Milvus")
.build();

MilvusClientV2 client = new MilvusClientV2(connectConfig);

CompletableFuture<GetResp> future = client.getAsync(GetReq.builder()
.collectionName("my_collection")
.ids(Collections.singletonList(0L))
.build());
GetResp response = future.get();