Data query

更新时间:
复制 MD 格式

Search indexes in Tablestore SDK for Python support basic queries, Boolean query, sorting and paging, aggregation, full-text search, and k-nearest neighbor (KNN) vector query.

Basic queries

The following table describes the basic queries supported by search indexes.

Query type

Description

Match all query

Matches all rows. Use to get the total row count or return random rows.

Term query

Retrieves data by exact match on a column value, similar to string matching.

Terms query

Matches rows where a column value equals any of the specified keywords. Equivalent to the SQL IN operator.

Prefix query

Matches rows where a column value starts with the specified prefix.

Range query

Matches rows where a column value falls within a specified range.

Wildcard query

Matches rows by using wildcard characters in the search string.

Exists query

Checks whether a specific column exists in a row. Also known as a NULL query or NULL-value query. Useful for sparse data.

Collapse (distinct)

Deduplicates results by a specified column so that each distinct value appears only once, ensuring diversity in the result set.

Geo query

Queries rows by geographic location. Includes three subtypes:

  • Geo-distance query: Matches rows within a circular area defined by a center point and radius.

  • Geo-bounding box query: Matches rows within a specified rectangular area.

  • Geo-polygon query: Matches rows within a specified polygon area.

Nested query

Queries child rows of nested fields.

Boolean query

A Boolean query retrieves data based on a combination of subqueries and returns the rows that meet the specified conditions. For more information, see Boolean query.

Sorting and paging

You can predefine a sorting method when you create a search index, or specify one at query time. For large result sets, use the limit and offset parameters or tokens to page through results. For more information, see Sorting and paging.

Aggregation

Aggregation operations return statistics such as minimum, maximum, sum, average, count, distinct count, and percentiles. You can also group results by field value, range, geographical location, filter, histogram, or date histogram, and run nested aggregations within each group. For more information, see Aggregation.

Full-text search

Full-text search finds rows that contain specified query strings. You can configure highlight parameters to highlight matching terms in the results. For more information, see Full-text search.

KNN vector query

KNN vector query performs an approximate nearest neighbor search to find the most similar data items to a given vector in a large-scale dataset. For more information, see KNN vector query.