Tüm Ürünler
Search
Belge Merkezi

Tablestore:Nested query

Son Güncelleme:Dec 01, 2026

İç içe geçmiş bir alanın alt satırlarındaki verileri sorgulamak için NestedQuery kullanın. İç içe geçmiş türler doğrudan sorgulanamaz; sorguyu bir NestedQuery ile sarmalayın, iç içe geçmiş alan yolunu belirtin ve bir alt sorgu ekleyin. Alt sorgu herhangi bir sorgu türü olabilir.

Önkoşullar

Parametreler

Parametre

Açıklama

tableName

Veri tablosunun adı.

indexName

Arama dizininin adı.

path

İç içe geçmiş alanın yolu. Örneğin, news.title, iç içe geçmiş news alanının içindeki title alt alanını ifade eder.

query

İç içe geçmiş alanın alt alanlarına karşı çalıştırılacak sorgu. Herhangi bir sorgu türü desteklenir.

scoreMode

Bir alan birden çok değer içerdiğinde kullanılacak puanlama modu.

InnerHits

İç içe geçmiş alanın alt alanları için yapılandırma. Aşağıdaki seçenekleri içerir:

  • sort: İç içe geçmiş alt satırları döndürmek için sıralama düzeni.

  • offset: İç içe geçmiş alan birden çok alt satır içerdiğinde başlangıç konumu.

  • limit: İç içe geçmiş alan birden çok alt satır içerdiğinde döndürülecek maksimum alt satır sayısı. Varsayılan: 3.

  • highlight: İç içe geçmiş alt alanlar için vurgulama ayarları. Ayrıntılar için bkz. Özet ve vurgulama.

Örnekler

Tek düzeyli iç içe geçmiş sorgu örneği

Col_Nested.Sub_Col_Keyword değeri "happy" olan satırları sorgular. Col_Nested, alt satırları Sub_Col_Keyword alt alanını içeren iç içe geçmiş bir alandır.

/**
 * Sample nested data for Col_Nested: '[{Sub_Col_Keyword: "happy"},{Sub_Col_Keyword: "sunny"}]'
 */
client.search({
    tableName: "<TABLE_NAME>",
    indexName: "<SEARCH_INDEX_NAME>",
    searchQuery: {
        offset: 0,
        limit: 10, // To get only the row count without retrieving specific data, set limit to 0. This prevents any rows from being returned.
        query: { // Set the query type to TableStore.QueryType.NESTED_QUERY.
            queryType: TableStore.QueryType.NESTED_QUERY,
            query: {
                path: "Col_Nested",
                query: {
                    queryType: TableStore.QueryType.TERM_QUERY,
                    query: {
                        fieldName: "Col_Nested.Sub_Col_Keyword",
                        term: "happy"
                    }
                },
            }
        },
        getTotalCount: true // TotalCount in the result indicates the total number of rows in the table. The default value is false, which means the total count is not returned.
    },
    columnToGet: { // The columns to return. You can set this to RETURN_SPECIFIED (return custom columns), RETURN_ALL (return all columns), RETURN_ALL_FROM_INDEX (return all columns from the search index), or RETURN_NONE (return no columns).
        returnType: TableStore.ColumnReturnType.RETURN_ALL
    }
}, function (err, data) {
    if (err) {
        console.log('error:', err);
        return;
    }
    console.log('success:', JSON.stringify(data, null, 2));
});

İç içe geçmiş sorguda özet ve vurgulama kullanımı örneği

Col_Nested iç içe geçmiş alanındaki Sub_Col_Text alt alanı tablestore ile eşleşen satırları bulmak ve sonuçlarda eşleşen terimleri vurgulamak için NestedQuery kullanın.

client.search({
    tableName: "<TABLE_NAME>",
    indexName: "<SEARCH_INDEX_NAME>",
    searchQuery: {
        offset: 0,
        limit: 10, // To get only the row count without retrieving specific data, set limit to 0. This prevents any rows from being returned.
        query: { // Set the query type to TableStore.QueryType.NESTED_QUERY.
            queryType: TableStore.QueryType.NESTED_QUERY,
            query: {
                path: "Col_Nested",
                query: {
                    queryType: TableStore.QueryType.MATCH_QUERY,
                    query: {
                        fieldName: "Col_Nested.Sub_Col_Text",
                        text: "tablestore"
                    }
                },
                innerHits: {
                    sort: {
                        sorters: [
                            {
                                scoreSort: {
                                    order: TableStore.SortOrder.SORT_ORDER_DESC
                                }
                            },
                            {
                                docSort: {
                                    order: TableStore.SortOrder.SORT_ORDER_ASC
                                }
                            },
                        ],
                    },
                    highlight: {
                        highlightParameters: [
                            {
                                fieldName:"Col_Nested.Sub_Col_Text",
                                preTag: "<b>",
                                postTag: "</b>",
                                fragmentsOrder: TableStore.HighlightFragmentOrder.TEXT_SEQUENCE,
                                fragmentSize: 20,
                                numberOfFragments: 3,
                            }
                        ]
                    }
                },
            }
        },
        getTotalCount: true // TotalCount in the result indicates the total number of rows in the table. The default value is false, which means the total count is not returned.
    },
    columnToGet: { // The columns to return. You can set this to RETURN_SPECIFIED (return custom columns), RETURN_ALL (return all columns), RETURN_ALL_FROM_INDEX (return all columns from the search index), or RETURN_NONE (return no columns).
        returnType: TableStore.ColumnReturnType.RETURN_ALL
    }
}, function (err, data) {
    if (err) {
        console.log('error:', err);
        return;
    }
    console.log('success:', JSON.stringify(data.rows, null, 2));

    printSearchHit(data.searchHits, "");
});

/**
 * Prints the content of searchHit.
 * @param searchHits The searchHits.
 * @param prefix The prefix to add for nested structures to print hierarchical information.
 */
function printSearchHit(searchHits, prefix) {
    TableStore.util.arrayEach(searchHits, function (searchHit) {
        if (searchHit.highlightResultItem != null) {
            console.log(prefix + "Highlight: \n");
            var strBuilder = ""
            for  (const [key,val]  of searchHit.highlightResultItem.highlightFields.entries()) {
                strBuilder += key + ":[";
                strBuilder += val.fragments.join(",") + "]\n";
                console.log(strBuilder);
            }
        }
        for  (const [key,val]  of searchHit.searchInnerHits.entries()) {
            console.log(prefix + "Path: " + key + "\n");
            console.log(prefix + "InnerHit: \n");
            printSearchHit(val.subSearchHits, prefix + "    ");
        }
    });
}

SSS

İlgili Kaynaklar