query()
The MilvusClient interface. This method queries entity(s) based on scalar field(s) filtered by boolean expression. Note that the order of the returned entities can not be guaranteed.
R<QueryResponse> query(QuerySimpleParam requestParam);
QuerySimpleParam
Use the QuerySimpleParam.Builder
to construct a QuerySimpleParam
object.
import io.milvus.param.highlevel.dml.QuerySimpleParam;
QuerySimpleParam.Builder builder = QuerySimpleParam.newBuilder();
Methods of QuerySimpleParam.Builder
:
Method |
Description |
Parameters |
---|---|---|
withCollectionName(collectionName) |
Set the collection name. Collection name cannot be empty or null. |
collectionName: The target collection name. |
withOutputFields(List<String> outputFields) |
Specifies output scalar fields (Optional). |
|
withFilter(String filter) |
Set the expression to query entities. For more information please refer to this doc. |
filter: The expression to query. |
withOffset(Long offset) |
Specify a position, the returned entities before this position will be ignored. Only take effect when the 'limit' value is specified.Default value is 0, start from begin. |
offset: A value to define the position. |
withLimit(Long limit) |
Specify a value to control the returned number of entities. Must be a positive value.Default value is 0, will return without limit. |
limit: A value to define the limit of returned entities. |
withConsistencyLevel(ConsistencyLevelEnum consistencyLevel) |
Consistency level used in the query. If no level is specified, will use default consistency. Please refer to ConsistencyLevelEnum in Misc. |
consistencyLevel: The consistency level used in the query. |
build() |
Construct a QuerySimpleParam object. |
N/A |
The QuerySimpleParam.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<QueryResponse>
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 valid
QueryResponse
held by theR
template.
Example
import io.milvus.param.*;
import io.milvus.response.QueryResultsWrapper;
import io.milvus.response.FieldDataWrapper;
import io.milvus.grpc.QueryResults;
QuerySimpleParam querySimpleParam = QuerySimpleParam.newBuilder()
.withCollectionName(COLLECTION_NAME)
.withOutFields(Lists.newArrayList("*"))
.withFilter(filter)
.withLimit(100L)
.withOffset(0L)
.build();
R<QueryResponse> response = client.query(param)
if (response.getStatus() != R.Status.Success.getCode()) {
System.out.println(response.getMessage());
}
for (QueryResultsWrapper.RowRecord rowRecord : response.getData().getRowRecords()) {
System.out.println(rowRecord);
}