You can use match all query to query the total number of rows in a table or obtain multiple rows of data.
Prerequisites
- The OTSClient instance is initialized. For more information, see Initialization.
- A data table is created. Data is written to the table.
- A search index is created for the table. For more information, see Create search indexes.
Parameters
Parameter | Description |
---|---|
table_name | The name of the base table. |
index_name | The name of the search index. |
offset | The position from which the current query starts. |
limit | The maximum number of rows that the current query returns.
To query only the number of matched rows but not detailed data, you can set Limit to 0. In this case, Tablestore returns the number of matched rows without data from the table. |
get_total_count | Specifies whether to return the total number of rows that match the query conditions.
By default, this parameter is set to false, which indicates that the total number
of rows that match the query conditions is not returned.
Query performance is affected when this parameter is set to true. |
collapse | Specifies that the returned results are collapsed based on the specified column. |
query_type | The query type. To use match query, set this parameter to QueryTypeConst::MATCH_ALL_QUERY. |
sort | The sorting method. The returned rows are sorted based on the specified method. For more information, see Sorting and paging. |
columns_to_get | Specifies whether to return all columns of each matched row.
|
Example
$request = array(
'table_name' => 'php_sdk_test',
'index_name' => 'php_sdk_test_search_index',
'search_query' => array(
'offset' => 0,
'limit' => 10,
'get_total_count' => true,
'collapse' => array(
'field_name' => 'keyword'
),
'query' => array(
'query_type' => QueryTypeConst::MATCH_ALL_QUERY
),
// 'sort' => array(// Set a specific sorting method if required.
// array(
// 'field_sort' => array(
// 'field_name' => 'keyword',
// 'order' => SortOrderConst::SORT_ORDER_ASC
// )
// ),
// ),
'token' => null,
),
'columns_to_get' => array(
'return_type' => ColumnReturnTypeConst::RETURN_SPECIFIED,
'return_names' => array('col1', 'col2')
)
);
$response = $otsClient->search($request);