All Products
Search
Document Center

Tablestore:Use post-query filters

Last Updated:Aug 11, 2026

Use the Tablestore SDK for Go to filter results after query and aggregation processing.

Prerequisites

Install the Tablestore Go SDK and initialize a client.

Description

A post-query filter uses SearchFilter to filter query results. The filter is applied after query and aggregation processing. Therefore, it does not change aggregation results and affects only returned rows and the matched-row count. You can use this feature to control when a query condition is evaluated. Proper use can improve query performance.

Important

The main query supports all query types supported by Search, but MatchAllQuery is not recommended. A filter supports only TermQuery, TermsQuery, RangeQuery, ExistsQuery, and BoolQuery values composed of these query types. BoolQuery supports MustQueries, MustNotQueries, and ShouldQueries but does not support FilterQueries. Only Keyword, Long, and Double fields can be filtered, and sorting and aggregation must be enabled for the field. A filter condition does not support Weight.

filter := (&search.SearchFilter{}).SetQuery(
    &search.TermQuery{FieldName: "status", Term: "active"},
)
searchQuery := search.NewSearchQuery().
    SetQuery(&search.TermQuery{FieldName: "category", Term: "books"}).
    SetSearchFilter(filter).
    SetGetTotalCount(true)

response, err := client.Search(&tablestore.SearchRequest{
    TableName:   "example_table",
    IndexName:   "example_index",
    SearchQuery: searchQuery,
})
if err != nil {
    log.Fatal(err)
}

fmt.Println(response.TotalCount)
fmt.Println(response.Rows)

Parameters

Name

Type

Description

Query (required)

search.Query

The filter condition. TermQuery, TermsQuery, RangeQuery, ExistsQuery, and BoolQuery combinations of these types are supported.

Response

Name

Type

Description

TotalCount

int64

The total number of matched rows. The value depends on SetGetTotalCount.

Rows

[]*tablestore.Row

The rows returned by the current query. The number does not exceed the value specified by SetLimit.

SearchHits

[]*tablestore.SearchHit

The search hits. Read this field when you use highlighting, nested inner hits, or relevance scores.

NextToken

[]byte

The token for the next page. If the value is not empty, pass it to the next query.

IsAllSuccess

bool

Indicates whether all index partitions were queried. If the value is false, partial results are returned and TotalCount may be less than the actual number of matched rows.

AggregationResults

search.AggregationResults

The aggregation results.

GroupByResults

search.GroupByResults

The grouping results.