すべてのプロダクト
Search
ドキュメントセンター

Tablestore:JSON クエリ

最終更新日:Aug 12, 2026

Tablestore SDK for Go を使用して、多次元インデックス内の JSON オブジェクトまたは JSON ネストフィールドをクエリします。

前提条件

開始する前に、以下の準備を完了してください。

  • Tablestore Go SDK をインストールし、クライアントを初期化します。

  • JSON フィールドを含む多次元インデックスが作成されていること。詳細については、「多次元インデックスの作成」をご参照ください。

説明

JSON フィールドは、オブジェクトとネストのインデックス作成をサポートします。オブジェクトは配列内のオブジェクト境界を保持しないため、異なるオブジェクトが異なるクエリ条件を満たす可能性があります。ネストは配列内の各オブジェクトを独立した子行としてインデックス化し、複数の条件が同じ配列要素内で一致することを保証します。

JSON インデックスタイプ

クエリ方法

JsonType_OBJECT

配列内のオブジェクト境界を保持しません。通常のクエリで子フィールドの完全なパス (profile.city など) を使用します。

JsonType_NESTED

同じオブジェクト内のフィールド関係を保持します。配列内のオブジェクトをクエリするには、Nested クエリを使用します。

説明

JSON フィールドの SubFieldSchemas には、ベクター子フィールドを含めることはできません。

オブジェクトフィールドのクエリ

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

// profile.city フィールドに対して Term クエリを実行
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)

ネストフィールドのクエリ

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

// orders 配列内の product フィールドに対して Nested クエリを実行
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)

パラメータ

Object フィールドは、選択されたクエリタイプのパラメーターを使用します。Nested フィールドは search.NestedQuery を使用します。一般的なクエリ設定については、「Term クエリ」をご参照ください。NestedQuery パラメーターについては、「Nested クエリ」をご参照ください。

オブジェクトフィールドのクエリ

名前

タイプ

説明

FieldName (必須)

文字列

JSON 子フィールドの完全なパス (profile.city など)。

クエリ値 (必須)

interface{}

名前とタイプは、選択したクエリタイプによって異なります。

ネストフィールドのクエリ

名前

タイプ

説明

Path (必須)

文字列

JsonType_NESTED フィールドのパス。

Query (必須)

search.Query

子フィールドに対するクエリ条件。

ScoreMode (オプション)

search.ScoreMode

子行からのスコアを結合する方法。