All Products
Search
Document Center

Tablestore:Query data in a Lastpoint index

Last Updated:Apr 30, 2026

This topic describes how to query data in a Lastpoint index by using Tablestore SDK for Java.

Usage notes

The Lastpoint index feature requires Tablestore SDK for Java V5.17.1 or later. Upgrade your SDK if you are running an earlier version.

Note

For information about how to download a new version of Tablestore SDK for Java, see Tablestore SDK for Java version history.

Prerequisites

Before you begin, ensure that you have:

Sample code

The following example calls the GetRange operation to read all rows from a Lastpoint index. The scan uses INF_MIN and INF_MAX as the start and end primary key values for all primary key columns to cover the full key range. If the response includes nextStartPrimaryKey, the loop continues reading from that position until all rows are retrieved.

private static void getRange(SyncClient client) {
    // Specify the name of the Lastpoint index.
    RangeRowQueryCriteria rangeRowQueryCriteria = new RangeRowQueryCriteria("<LASTPOINT_INDEX_NAME>");
    
    // Set the start primary key to INF_MIN and the end primary key to INF_MAX for each primary key column.
    PrimaryKey startPrimaryKey = PrimaryKeyBuilder.createPrimaryKeyBuilder()
            .addPrimaryKeyColumn("_#h", PrimaryKeyValue.INF_MIN)
            .addPrimaryKeyColumn("_m_name", PrimaryKeyValue.INF_MIN)
            .addPrimaryKeyColumn("_data_source", PrimaryKeyValue.INF_MIN)
            .addPrimaryKeyColumn("_tags", PrimaryKeyValue.INF_MIN)
            .build();
    rangeRowQueryCriteria.setInclusiveStartPrimaryKey(startPrimaryKey);
    PrimaryKey endPrimaryKey = PrimaryKeyBuilder.createPrimaryKeyBuilder()
            .addPrimaryKeyColumn("_#h", PrimaryKeyValue.INF_MAX)
            .addPrimaryKeyColumn("_m_name", PrimaryKeyValue.INF_MAX)
            .addPrimaryKeyColumn("_data_source", PrimaryKeyValue.INF_MAX)
            .addPrimaryKeyColumn("_tags", PrimaryKeyValue.INF_MAX)
            .build();
    rangeRowQueryCriteria.setExclusiveEndPrimaryKey(endPrimaryKey);
    // Set the maximum number of versions to 1. Time series tables do not support multiple versions.
    rangeRowQueryCriteria.setMaxVersions(1);
    
    System.out.println("Scan results:");
    while (true) {
        GetRangeResponse getRangeResponse = client.getRange(new GetRangeRequest(rangeRowQueryCriteria));
        for (Row row : getRangeResponse.getRows()) {
            System.out.println(row);
        }
        // If nextStartPrimaryKey is not null, continue reading.
        if (getRangeResponse.getNextStartPrimaryKey() != null) {
            rangeRowQueryCriteria.setInclusiveStartPrimaryKey(getRangeResponse.getNextStartPrimaryKey());
        } else {
            break;
        }
    }
}

What's next

  • For information about how to read data by using Tablestore SDK for Java, see Read data.

  • To query data in a Lastpoint index using advanced methods such as Boolean query, full-text search, prefix query, and fuzzy query, create a search index for the Lastpoint index. For more information, see Retrieve a Lastpoint index.