Skip to main content

Query Operations

Query Milvus through the Builder API or Mappers, or write SQL supported by JDBC-Milvus. See JDBC Milvus for connection setup.

Before Querying

The examples use the existing, loaded book_vectors collection; see Preparing the Collection for its definition. Load the collection before scalar or vector queries. See Pagination for paged reads.

Entity Mapping

FLOAT_VECTOR fields accept List<Float> directly; the list length must match the field dimension. See Type Support for other vector types.

@Table("book_vectors")
public class BookVector {
@Column(value = "book_id", primary = true)
private Long bookId;
private String title;
@Column("word_count")
private Integer wordCount;
@Column("book_intro")
private List<Float> bookIntro;
// Getters and setters omitted
}

Keys are assigned by the application or generated by collection AutoID; see Key Generation.

Executing Query Commands

JdbcTemplate jdbc = new JdbcTemplate(dataSource);

List<BookVector> rows = jdbc.queryForList(
"SELECT * FROM book_vectors WHERE book_id = ?",
new Object[] { 1001L }, BookVector.class);

Querying Through Different APIs

LambdaTemplate lambda = new LambdaTemplate(dataSource);
BookVector item = lambda.query(BookVector.class)
.eq(BookVector::getBookId, 1001L)
.queryForObject();

Scalar queries use native Query; vector queries use Search.

Vector field mapping, search metrics, and scalar filters are described in Vector Operations.

Query

Field selection, entity and Map results, scalar results, and COUNT(*) are supported. Computed projections, DISTINCT, and general SQL aggregates are not supported. For predicate syntax and optional conditions, see Builder API.

Map Queries

Entry pointMap key names
Entity-based asMap()Java property names
queryFreedomMilvus field names
BaseMapper Map query methodsRegistered entity property names

See Map Writes for writes and NULL properties.

Vector Queries

See Vector Operations for vector mapping, search metrics, and scalar filters.

Query Execution Options

Mapper files accept statementType, timeout, and fetchSize; their effect follows the driver settings. For resultSetType, keep DEFAULT or use FORWARD_ONLY. Scrollable result sets (SCROLL_INSENSITIVE and SCROLL_SENSITIVE) are not supported. See Execution Options for XML configuration.

See Reading Results for result columns.