Tüm Ürünler
Search
Belge Merkezi

Tablestore:Çok koşullu sorgu

Son Güncelleme:Oct 02, 2026

Boolean sorgusu (BoolQuery), bir veya daha fazla alt sorgu içerir. Satırların sorgu koşullarını karşılayıp karşılamadığını bu alt sorgularla denetler. Her alt sorgu, başka bir Boolean sorgusu da dahil olmak üzere herhangi bir sorgu türünde olabilir.

Önkoşullar

Parametreler

Parametre

Açıklama

tableName

Veri tablosunun adı.

indexName

Arama dizininin adı.

mustQueries

Sorgu listesi. Satırın tüm alt sorgularla eşleşmesi gerekir. Bu, AND operatörüne eşdeğerdir.

mustNotQueries

Sorgu listesi. Satırın alt sorgulardan hiçbiriyle eşleşmemesi gerekir. Bu, NOT operatörüne eşdeğerdir.

filterQueries

Sorgu listesi. Satırın filtredeki tüm alt sorgularla eşleşmesi gerekir. Filtre bir sorguya benzer ancak eşleşen filtre sayısına göre alaka puanı hesaplamaz.

shouldQueries

Sorgu listesi. Satır bu alt sorgularla eşleşebilir. Bu, OR operatörüne eşdeğerdir.

Satırın eşleşme olarak kabul edilmesi için en azından belirtilen minimum sayıda shouldQueries alt sorgusuyla eşleşmesi gerekir.

Satırın eşleştiği shouldQueries alt sorgusu sayısı arttıkça alaka puanı yükselir.

minimumShouldMatch

Eşleşmesi gereken minimum shouldQueries sayısı. Aynı düzeyde yalnızca shouldQueries varsa varsayılan değer 1'dir. Aynı düzeyde mustQueries, mustNotQueries ve filterQueries gibi diğer sorgular varsa varsayılan değer 0'dır.

Örnek

Aşağıdaki örnek, Boolean sorgu gerçekleştirmek için bir BoolQuery'nin nasıl oluşturulacağını gösterir.

var client = require('../client');
var TableStore = require('../../index.js');
var Long = TableStore.Long;
/**
 * Use a boolean query to implement (col2 < 4 OR col3 < 5) OR (col2 = 4 AND (col3 = 5 OR col3 = 6)). The logic is as follows:
 * boolQuery1 = rangeQuery(col2 < 4) OR rangeQuery(col3 < 5)
 * boolQuery2 = termQuery(col3 = 5) OR termQuery(col3 = 6)
 * boolQuery3 = termQuery(col2 = 4) AND boolQuery2
 * boolQuery4 = boolQuery1 OR boolQuery3
 */
client.search({
    tableName: "sampleTable",
    indexName: "sampleSearchIndex",
    searchQuery: {
        offset: 0, // The query offset.
        limit: 10, // To get only the row count without retrieving data, set limit to 0. This returns no rows.
        getTotalCount: false, // TotalCount in the result indicates the total number of rows in the table. The default value is false, which means it is not returned.
        query: { // Construct boolQuery4. Set the query condition to match at least one of boolQuery1 and boolQuery3.
            queryType: TableStore.QueryType.BOOL_QUERY,
            query: {
                shouldQueries: [ // You can use mustQueries, shouldQueries, or mustNotQueries.
                    { // Construct boolQuery1. Set the query condition to match at least one of "Query Condition 1" and "Query Condition 2".
                        queryType: TableStore.QueryType.BOOL_QUERY,
                        query: {
                            // shouldQueries: The query condition is that the value of col2 is less than 4 or the value of col3 is less than 5.
                            shouldQueries:[
                                {
                                    // Query Condition 1: rangeQuery, the value of col2 is less than 4.
                                    queryType: TableStore.QueryType.RANGE_QUERY,
                                    query:{
                                        fieldName: "col2",
                                        rangeTo: 4
                                    }
                                },
                                {
                                    // Query Condition 2: rangeQuery, the value of col3 is less than 5.
                                    queryType: TableStore.QueryType.RANGE_QUERY,
                                    query:{
                                        fieldName: "col3",
                                        rangeTo: 5
                                    }
                                }
                            ],
                            minimumShouldMatch:1

                        }
                    },
                    { // Construct boolQuery3. Set the query condition to match both "Query Condition 3" and boolQuery2.
                        queryType: TableStore.QueryType.BOOL_QUERY,
                        query: {
                            mustQueries: [
                                // mustQueries: The query condition is that the value of col2 is 4, and the value of col3 is 5 or 6.
                                {
                                    // Query Condition 3: termQuery, the value of col2 is 4.
                                    queryType:TableStore.QueryType.TERM_QUERY,
                                    query: {
                                        fieldName : "col2",
                                        term: 4
                                    }
                                },
                                { // Construct boolQuery2: Set the query condition to match at least one of "Query Condition 4" and "Query Condition 5".
                                    queryType: TableStore.QueryType.BOOL_QUERY,
                                    query: {
                                        // shouldQueries: The query condition is that the value of col3 is 5 or 6.
                                        shouldQueries:[
                                            {
                                                // Query Condition 4: termQuery, the value of col3 is 5.
                                                queryType: TableStore.QueryType.TERM_QUERY,
                                                query:{
                                                    fieldName:"col3",
                                                    term: 5
                                                }
                                            },
                                            {
                                                // Query Condition 5: termQuery, the value of col3 is 6.         
                                                queryType: TableStore.QueryType.TERM_QUERY,
                                                query:{
                                                    fieldName:"col3",
                                                    term: 6
                                                }
                                            }
                                        ],
                                        minimumShouldMatch:1
                                    }
                                }
                            ]
                        }
                    }
                ],
                minimumShouldMatch: 1 // This is valid only for shouldQueries. It specifies the minimum number of conditions to match.
            }
        },
    },
    columnToGet: { // Specifies the columns to return. Valid values: RETURN_SPECIFIED (returns custom columns), RETURN_ALL (returns all columns), RETURN_ALL_FROM_INDEX (returns all columns from the search index), and RETURN_NONE (returns no columns).       
        returnType: TableStore.ColumnReturnType.RETURN_SPECIFIED,
        returnNames: ["col2", "col3", "col4"]
    }
}, function (err, data) {
    if (err) {
        console.log('error:', err);
        return;
    }
    console.log('success:', JSON.stringify(data, null, 2));
});

SSS

İlgili Başlıklar