milvus-logo
LFAI
< Docs
  • Python
    • MilvusClient

query()

This method queries entities that meet specific criteria in a collection..

Invocation

query(
    collection_name,
    filter,
    output_fields,
    timeout
)

Parameters

ParameterDescriptionTypeRequired
collection_nameName of the collection to query.StringTrue
filterFilter used to query data.StringTrue
output_fieldsA list of fields to return. If you leave this parameter empty, all fields excluding the vector field will be returned.list[String]False
timeoutAn optional duration of time in seconds to allow for the RPC. If it is set to None, the client keeps waiting until the server responds or error occurs.FloatFalse

Return

A list of dictionaries, excluding the vector field.

Raises

ValueError: Error if the collection is missing.

Example

  • Query data in a fixed schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.query(
        filter='book_id in [2,4,6,8]',
        output_fields=["book_id", "book_intro"] # book_id and book_intro are pre-defined in the schema.
    )
    
  • Query data in a dynamic schema:

    from pymilvus import MilvusClient
    
    client = MilvusClient(uri, token)
    
    client.query(
        filter='$meta["claps"] > 30 and responses < 10',
        output_fields=["title", "claps", "responses"] # claps and responses are not defined in the schema.
    )
    

    The preceding code block shows how to access fields claps and responses that are not defined in the schema.