queryAsync()

Queries entities in a collection asynchronously and returns a future.

public CompletableFuture<QueryResp> queryAsync(QueryReq request)

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

Request Syntax

CompletableFuture<QueryResp> future = client.queryAsync(QueryReq.builder()
    .collectionName(String collectionName)
    .filter(String filter)
    .outputFields(List<String> outputFields)
    .build());

For the full list of QueryReq builder methods, refer to query().

RETURNS:

CompletableFuture

A future completed with a QueryResp, or completed exceptionally when the operation fails.

EXCEPTIONS:

  • MilvusClientException

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

Example

import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.vector.request.QueryReq;
import io.milvus.v2.service.vector.response.QueryResp;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;

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

MilvusClientV2 client = new MilvusClientV2(connectConfig);

CompletableFuture<QueryResp> future = client.queryAsync(QueryReq.builder()
        .collectionName("my_collection")
        .filter("age > 20")
        .outputFields(Arrays.asList("name", "age"))
        .build());
QueryResp response = future.get();

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?