All Products
Search
Document Center

Tablestore:JSON queries

Last Updated:Aug 11, 2026

Use the Tablestore SDK for Go to query JSON Object or JSON Nested fields in a search index.

Prerequisites

Before you begin, complete the following preparations:

Description

A JSON field supports Object and Nested indexing. Object does not preserve object boundaries within an array, so different objects can satisfy different query conditions. Nested indexes each object in an array as an independent child row and ensures that multiple conditions match within the same array element.

JSON index type

Query method

JsonType_OBJECT

Does not preserve object boundaries in an array. Use the full child-field path in a regular query, such as profile.city.

JsonType_NESTED

Preserves field relationships within the same object. Use NestedQuery to query objects in an array.

Note

SubFieldSchemas of a JSON field cannot contain a Vector child field.

Query an Object field

tableName := "example_table"
indexName := "example_index"

query := &search.TermQuery{FieldName: "profile.city", Term: "hangzhou"}
searchQuery := search.NewSearchQuery().
    SetQuery(query).
    SetLimit(10).
    SetGetTotalCount(true)

response, err := client.Search(&tablestore.SearchRequest{
    TableName:   tableName,
    IndexName:   indexName,
    SearchQuery: searchQuery,
    ColumnsToGet: &tablestore.ColumnsToGet{
        ReturnAllFromIndex: true,
    },
})
if err != nil {
    log.Fatal(err)
}

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

Query a Nested field

tableName := "example_table"
indexName := "example_index"

query := &search.NestedQuery{Path: "orders", Query: &search.TermQuery{FieldName: "orders.product", Term: "book"}, ScoreMode: search.ScoreMode_None}
searchQuery := search.NewSearchQuery().
    SetQuery(query).
    SetLimit(10).
    SetGetTotalCount(true)

response, err := client.Search(&tablestore.SearchRequest{
    TableName:   tableName,
    IndexName:   indexName,
    SearchQuery: searchQuery,
    ColumnsToGet: &tablestore.ColumnsToGet{
        ReturnAllFromIndex: true,
    },
})
if err != nil {
    log.Fatal(err)
}

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

Parameters

An Object field uses parameters of the selected query type. A Nested field uses search.NestedQuery. For common query configurations, see Term query. For NestedQuery parameters, see Nested query.

Object field query

Name

Type

Description

FieldName (required)

string

The full path of the JSON child field, such as profile.city.

Query value (required)

interface{}

The name and type depend on the selected query type.

Nested field query

Name

Type

Description

Path (required)

string

The path of the JsonType_NESTED field.

Query (required)

search.Query

The query condition on child fields.

ScoreMode (optional)

search.ScoreMode

The method used to combine scores from child rows.