All Products
Search
Document Center

Tablestore:Query Lastpoint data by using a search index

Last Updated:Aug 04, 2026

Use Tablestore SDK for Java to create a search index on a Lastpoint index and query the latest data of each time series by data field conditions.

Prerequisites

Install the Tablestore SDK for Java and initialize a client. Lastpoint indexes require version 5.17.1 or later. We recommend that you use the latest version.

Description

Direct reads from a Lastpoint index locate data by primary key range. To filter the latest data by data fields with Boolean queries, full-text search, geo queries, or aggregations, create a search index on the Lastpoint index and call search. For more information about query capabilities, see Search indexes.

public CreateSearchIndexResponse createSearchIndex(CreateSearchIndexRequest request) throws TableStoreException, ClientException
public SearchResponse search(SearchRequest request) throws TableStoreException, ClientException

Create a search index

Only fields included in the search index schema can be queried. The _tags field of a Lastpoint index is a string array and must be mapped as a Keyword array. Map other data fields to their corresponding types.

The following example creates example_search_index on example_lastpoint_index and indexes the tags, speed, and status fields.

List<FieldSchema> fieldSchemas = Arrays.asList(
        new FieldSchema("_tags", FieldType.KEYWORD)
                .setIndex(true).setIsArray(true),
        new FieldSchema("speed", FieldType.DOUBLE)
                .setIndex(true).setEnableSortAndAgg(true),
        new FieldSchema("status", FieldType.KEYWORD)
                .setIndex(true).setEnableSortAndAgg(true));

IndexSchema indexSchema = new IndexSchema();
indexSchema.setFieldSchemas(fieldSchemas);

CreateSearchIndexRequest request = new CreateSearchIndexRequest();
request.setTableName("example_lastpoint_index");
request.setIndexName("example_search_index");
request.setIndexSchema(indexSchema);

client.createSearchIndex(request);

Query the latest data

Creating a search index is asynchronous. Run queries after the index status changes to RUNNING and the data synchronization phase changes to INCR.

The following example uses a range query to retrieve Lastpoint rows in which speed is greater than 20.0. The query returns the total number of matching rows and all columns.

RangeQuery rangeQuery = new RangeQuery();
rangeQuery.setFieldName("speed");
rangeQuery.greaterThan(ColumnValue.fromDouble(20.0));

SearchQuery searchQuery = new SearchQuery();
searchQuery.setQuery(rangeQuery);
searchQuery.setGetTotalCount(true);

SearchRequest request = new SearchRequest(
        "example_lastpoint_index",
        "example_search_index",
        searchQuery);
SearchRequest.ColumnsToGet columnsToGet =
        new SearchRequest.ColumnsToGet();
columnsToGet.setReturnAll(true);
request.setColumnsToGet(columnsToGet);

SearchResponse response = client.search(request);
System.out.println(response.getTotalCount());
response.getRows().forEach(System.out::println);

Parameters

Create search index request

CreateSearchIndexRequest contains the following parameters.

Name

Type

Description

tableName (required)

String

The Lastpoint index name. A Lastpoint index is used as a data table when you create a search index.

indexName (required)

String

The search index name.

indexSchema (required)

IndexSchema

The search index schema, including field schemas, index settings, and presorting settings.

Index fields

Each element in indexSchema.fieldSchemas[] is of the FieldSchema type. The following parameters configure the fields in the example.

Name

Type

Description

fieldName (required)

String

The field name in the Lastpoint index.

fieldType (required)

FieldType

The search index field type. The type must match the value type in the Lastpoint index.

index (optional)

boolean

Specifies whether to index the field. Default value: true.

isArray (optional)

boolean

Specifies whether the field is an array. Default value: false. Set this parameter to true for _tags.

enableSortAndAgg (optional)

boolean

Specifies whether sorting and aggregations are enabled. Default value: true. Text fields do not support sorting or aggregations.

Search request

SearchRequest contains the following parameters.

Name

Type

Description

tableName (required)

String

The Lastpoint index name.

indexName (required)

String

The name of the search index on the Lastpoint index.

searchQuery (required)

SearchQuery

The query configuration. The example sets query to RangeQuery and sets getTotalCount to true to return the total number of matching rows. For supported query types and parameters, see Data query.

columnsToGet (optional)

SearchRequest.ColumnsToGet

The columns to return. If this parameter is not specified, only primary key columns are returned. The example uses returnAll to return all columns.

Response

SearchResponse contains the following operation-specific fields.

Field

Type

Description

rows

List<Row>

Call getRows() to obtain the Lastpoint rows returned by the request.

totalCount

long

Call getTotalCount() to obtain the total number of matching rows. This field is returned only if getTotalCount is true.

nextToken

byte[]

Call getNextToken() to obtain the start position of the next query. An empty value indicates that no more data is available.

isAllSuccess

boolean

Call isAllSuccess() to check whether the query is successful.