All Products
Search
Document Center

Tablestore:How do I increase the value of the limit parameter to 1000 when I call the Search operation of the search index feature to query data?

Last Updated:Sep 30, 2024

To increase the number of returned rows in a query, you can call the Search operation in search indexes. When only data in search indexes is queried, the value of the limit parameter automatically increases to 1000. When data in data tables is queried, the value of the limit parameter is 100. This topic describes how to increase the value of the limit parameter to 1000 when you call the Search operation of the search index feature to query data.

Procedure

When you call the Search operation of the search index feature to query data, you can use the ColumnsToGet parameter to specify the columns that you want to return. If the columns that you specify are included in the search index, the value of the limit parameter is automatically increased to 1000. To increase the value of the limit parameter to 1000, you can use the ColumnsToGet parameter to specify the columns that are included in the search index or set the ReturnAllColumnsFromIndex parameter to true.

Examples

The following sample code provides an example on how to increase the value of the limit parameter to 1000 by configuring the ColumnsToGet parameter in SearchRequest in Tablestore SDK for Java. The method to increase the value of the limit parameter is similar in Tablestore SDKs for other programming languages.

SearchQuery searchQuery = new SearchQuery();
searchQuery.setQuery(new MatchAllQuery());
searchQuery.setLimit(1000);

SearchRequest searchRequest = new SearchRequest(tableName, indexName, searchQuery);

// Method 1: Set the columns parameter in the ColumnsToGet parameter to the columns that are included in the search index to return specific attribute columns in the search index.  
ColumnsToGet columnsToGet = new ColumnsToGet();
columnsToGet.setReturnAll(false);
// Set the columns parameter to the names of columns in the search index. 
columnsToGet.setColumns(Arrays.asList("field_1", "field_2", "field_3"));  
searchRequest.setColumnsToGet(columnsToGet);

// Method 2: Set the returnAllColumnsFromIndex parameter in ColumnsToGet to true to return all attribute columns in the search index. 
// Tablestore SDK for Java V5.6.1 or later supports the returnAllColumnsFromIndex parameter. 
ColumnsToGet columnsToGet = new ColumnsToGet();
columnsToGet.setReturnAllFromIndex(true);
searchRequest.setColumnsToGet(columnsToGet);

SearchResponse response = client.search(searchRequest);