query()

This operation conducts a scalar filtering with a specified boolean expression.

await milvusClient.query(data)

Request Syntax

 milvusClient.query({
    db_name: string,
    collection_name: string,
    partition_names?: string[];
    output_fields?: string[];
    ids?: string[] | number[];
    filter?: string;
    offset?: number;
    limit?: number;
    consistency_level?: ConsistencyLevelEnum;
    exprValues?: keyValueObj;
})

PARAMETERS:

  • db_name (string) -

    The name of the database that holds the target collection.

  • collection_name (string) -

    [REQUIRED]

    The name of an existing collection.

  • partition_names (string[]) -

    The name of the partitions to query.

  • output_fields (string[]) -

    A list of field names to include in each entity in return.

    The value defaults to None. If left unspecified, all fields are selected as the output fields.

  • ids (string[] | number[]) -

    The IDs of the entities to query.

  • filter (string) -

    A scalar filtering condition to filter matching entities.

    You can set this parameter to an empty string to skip scalar filtering. To build a scalar filtering condition, refer to Boolean Expression Rules.

  • offset (number) -

    The number of records to skip in the query result.

    You can use this parameter in combination with limit to enable pagination.

    The sum of this value and limit should be less than 16,384.

  • limit (number) -

    The number of records to return in the query result.

    You can use this parameter in combination with offset to enable pagination.

    The sum of this value and offset should be less than 16,384.

  • consistency_level (ConsistencyLevelEnum) -

    The consistency level of the target collection.

    The value defaults to the one specified when you create the current collection, with options of Strong (0), Bounded (1), Session (2), and Eventually (3).

    Consistency in a distributed database specifically refers to the property that ensures every node or replica has the same view of data when writing or reading data at a given time.

    Milvus supports four consistency levels: Strong, Bounded Staleness, Session, and Eventually. The default consistency level in Milvus is Bounded Staleness.

    You can easily tune the consistency level when conducting a vector similarity search or query to make it best suit your application.

  • timeout (number) -

    The timeout duration for this operation. Setting this to None indicates that this operation timeouts when any response arrives or any error occurs.

  • order_by_fields (OrderByFields) -

    The fields to order the query results by. Optional.

  • order_by (OrderByFields) -

    Alias for order_by_fields. Optional.

RETURNS Promise

This method returns a promise that resolves to a QueryResults object.

{
    data: Record<string, any>[],
    status:  ResStatus
}

PARAMETERS:

  • data (Record[]) - The matched rows. Each entry is keyed by field name and carries the value for every requested output_fields entry plus the primary key. When enable_dynamic_field is true on the collection, dynamic-field values appear inline alongside declared fields.

  • ResStatus A ResStatus object.

    • code (number) -

      A code that indicates the operation result. It remains 0 if this operation succeeds.

    • error_code (string | number) -

      An error code that indicates an occurred error. It remains Success if this operation succeeds.

    • reason (string) -

      The reason that indicates the reason for the reported error. It remains an empty string if this operation succeeds.

Example

const milvusClient = new MilvusClient({
    address: 'localhost:19530',
    token: 'root:Milvus',
});
 const queryResults = await milvusClient.query({
   collection_name: 'my_collection',
   filter: "age in [1,2,3,4,5,6,7,8]",
   output_fields: ["age"],
 });

Try Managed Milvus for Free

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

Get Started
Feedback

Was this page helpful?