All Products
Search
Document Center

Tablestore:Data query

Last Updated:Feb 11, 2025

This topic describes the data query features provided by search indexes when you use Tablestore SDK for Python to query data. The data query features include basic queries, Boolean query, sorting and paging, aggregation, full-text search, and k-nearest neighbor (KNN) vector query.

Basic queries

The following table describes basic queries supported by search indexes.

Query type

Description

Match all query

This query matches all rows in a table to query the total number of rows in the table or return multiple random rows.

Term query

This query uses exact matches to retrieve data from a data table. A term query is similar to a query based on string matching.

Terms query

This query allows you to specify multiple keywords to search for the rows that match at least one of the keywords. A row of data is returned if the column value matches at least one of the keywords. Terms queries can be used in the same manner as the IN operator in SQL statements.

Prefix query

This query retrieves data that contains the specified prefix from a data table.

Range query

This query retrieves data that falls within the specified range.

Wildcard query

This query retrieves data that matches a string containing wildcard characters.

Exists query

This query is also called NULL query or NULL-value query, which is used in sparse data to determine whether a column of a row exists.

Collapse (distinct)

This query collapses the result set based on a specific column to display data of the specified type only once in the returned results, ensuring the diversity of the result types.

Geo query

Geo queries are classified into the following types: geo-distance query, geo-bounding box query, and geo-polygon query.

  • Geo-distance query: This query allows you to specify a circular geographical area that is defined by a central point and a radius as a query condition. Tablestore returns the rows in which the value of the specified field falls within the circular geographical area.

  • Geo-bounding box query: This query allows you to specify a rectangular geographical area as a query condition. Tablestore returns the rows in which the value of the specified field falls within the rectangular geographical area.

  • Geo-polygon query: This query allows you to specify a polygon geographical area as a query condition. Tablestore returns the rows in which the value of the specified field falls within the polygon geographical area.

Nested query

This query retrieves the data in the child rows of Nested fields.

Boolean query

A Boolean query retrieves data in a data table based on a combination of subqueries. Tablestore returns the rows that meet the subquery conditions. For more information, see Boolean query.

Sorting and paging

You can predefine a sorting method when you create a search index or specify a sorting method when you use a search index to query data. This way, the rows that meet the query conditions are returned based on the order that you predefined or specified. If a large number of rows are included in the response, you can locate data by configuring the limit and offset parameters or by using tokens. For more information, see Sorting and paging.

Aggregation

You can perform aggregation operations to obtain the minimum value, maximum value, sum, average value, count and distinct count of rows, and percentile statistics. You can also perform aggregation operations to group results by field value, range, geographical location, filter, histogram, or date histogram, perform nested queries, and query the rows that are obtained from the results of an aggregation operation in each group. You can perform multiple aggregation operations for complex queries. For more information, see Aggregation.

Full-text search

You can use full-text search to quickly find rows of data that contain the query strings from a table. Full-text search is widely used in fields, such as search engines, databases, and document management systems. You can configure highlight parameters to highlight the query strings in the segments of the rows that meet the query conditions. For more information, see Full-text search.

KNN vector query

You can use the KNN vector query feature to perform an approximate nearest neighbor search based on vectors. This way, you can find data items that have the highest similarity to the vector that you want to query in a large-scale dataset. For more information, see KNN vector query.