Tüm Ürünler
Search
Belge Merkezi

Tablestore:Boolean query

Son Güncelleme:Oct 09, 2026

Boolean sorgu (BoolQuery), bir veya daha fazla alt sorgu içerir ve verilerin belirtilen sorgu koşullarını karşılayıp karşılamadığını belirlemek için bu alt sorguları kullanır. Her alt sorgu, başka bir BoolQuery dahil olmak üzere herhangi bir sorgu türünde olabilir.

API işlemleri

Boolean sorguyu Search veya ParallelScan API işlemiyle çalıştırabilirsiniz. Sorgu türü BoolQuery şeklindedir.

Parametreler

Parametre

Açıklama

mustQueries

Sorgu listesi. Bir veri satırının eşleşme olarak kabul edilmesi için tüm alt sorgularla eşleşmesi gerekir. Bu, AND operatörüne eşdeğerdir.

mustNotQueries

Sorgu listesi. Bir veri satırının eşleşme olarak kabul edilmesi için alt sorgulardan hiçbiriyle eşleşmemesi gerekir. Bu, NOT operatörüne eşdeğerdir.

filterQueries

Sorgu listesi. Bir veri satırının eşleşme olarak kabul edilmesi için tüm alt filtrelerle eşleşmesi gerekir. Filtre, bir sorguya benzer ancak eşleşen filtre sorgusu sayısına göre bir alaka puanı hesaplamaz.

shouldQueries

Sorgu listesi. Bu sorgular eşleşebilir veya eşleşmeyebilir. Bu, OR operatörüne eşdeğerdir.

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

Eşleşen shouldQueries alt sorgusu sayısı arttıkça genel alaka puanı yükselir.

minimumShouldMatch

Eşleşmesi gereken minimum shouldQueries alt sorgusu 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.

getTotalCount

Eşleşen toplam satır sayısının döndürülüp döndürülmeyeceğini belirtir. Varsayılan değer false'tur.

Eşleşen toplam satır sayısının döndürülmesi sorgu performansını etkileyebilir.

tableName

Veri tablosunun adı.

indexName

Arama dizininin adı.

columnsToGet

Tüm sütunların döndürülüp döndürülmeyeceğini belirtir. Bu ayar, returnAll ve columns parametrelerini içerir.

returnAll varsayılan değeri false'tur; bu, tüm sütunların döndürülmediği anlamına gelir. Bu durumda, döndürülecek sütunları belirtmek için columns parametresini kullanabilirsiniz. Döndürülecek sütunları belirtmezseniz yalnızca birincil anahtar sütunları döndürülür.

returnAll değerini true olarak ayarlarsanız tüm sütunlar döndürülür.

Kullanım

Boolean sorguyu konsol, komut satırı arayüzü veya SDK kullanarak çalıştırabilirsiniz. Başlamadan önce aşağıdaki adımları tamamlayın.

Konsolu kullanma

  1. Index Management sekmesine gidin.

    1. Table Store konsolunda oturum açın.

    2. Üst gezinme çubuğundan bir kaynak grubu ve bölge seçin.

    3. Overview sayfasında örnek adını tıklayın veya Actions sütunundaki Instance Management seçeneğini tıklayın.

    4. Instance Details sekmesinde, Data Table List sekmesinden veri tablosu adını tıklayın veya Actions sütunundaki Index Management seçeneğini tıklayın.

  2. Index Management sekmesinde hedef Arama Dizinini bulun ve Actions sütunundaki Search seçeneğini tıklayın.

  3. Query Data iletişim kutusundan verileri sorgulayabilirsiniz.

    1. Varsayılan olarak tüm sütunlar döndürülür. Belirli sütunları döndürmek için Retrieve All Columns seçeneğini kapatın ve virgülle ayırarak sütun adlarını girin.

      Not

      Table Store varsayılan olarak veri tablosunun birincil anahtar sütunlarını döndürür.

    2. Mantıksal bir operatör seçin: And, Or veya Not.

      And seçerseniz sorgu, belirtilen tüm koşulları karşılayan verileri döndürür. Or seçerseniz sorgu, belirtilen koşullardan en az birini karşılayan verileri döndürür. Not seçerseniz sorgu, belirtilen koşulları karşılamayan verileri döndürür.

    3. Bir dizin alanı seçin, Add seçeneğini tıklayın, ardından dizin alanı için sorgu türünü ayarlayın ve bir değer girin.

      Gerekirse birden fazla dizin alanı için sorgu yapılandırmaları eklemek üzere bu adımı tekrarlayabilirsiniz.

    4. Varsayılan olarak sıralama devre dışıdır. Sonuçları belirli bir alana göre sıralamak için Enable Sorting seçeneğini açın, sıralama alanını ekleyin ve sıralama düzenini yapılandırın.

    5. Varsayılan olarak toplamlama devre dışıdır. Belirli bir alanda istatistiksel toplamlama yapmak için Enable Aggregation seçeneğini açın, toplamlama için alanı ekleyin ve toplamlama ayarlarını yapılandırın.

  4. OK seçeneğini tıklayın.

    Sorgu sonuçları Index Management sekmesinde görüntülenir.

Komut satırı arayüzünü kullanma

Bir arama dizininden veri sorgulamak için komut satırı arayüzünde search komutunu çalıştırın. Daha fazla bilgi için bkz. Arama dizini.

  1. search_index arama dizinini kullanarak tablodan veri sorgulamak için search komutunu çalıştırın. Bu komut, dizine alınmış tüm sütunları döndürür.

    search -n search_index --return_all_indexed
  2. İstendiğinde sorgu koşullarını girin. Aşağıda bir örnek verilmiştir:

    {
        "Offset": -1,
        "Limit": 10,
        "Collapse": null,
        "Sort": null,
        "GetTotalCount": true,
        "Token": null,
        "Query": {
            "Name": "BoolQuery",
            "Query": {
                "MinimumShouldMatch": null,
                "MustQueries": null,
                "MustNotQueries": null,
                "FilterQueries": null,
                "ShouldQueries": [{
                    "Name": "RangeQuery",
                    "Query": {
                        "FieldName": "gid",
                        "From": null,
                        "To": 10,
                        "IncludeLower": false,
                        "IncludeUpper": false
                    }
                }, {
                    "Name": "TermQuery",
                    "Query": {
                        "FieldName": "gid",
                        "Term": 77
                    }
                }]
            }
        },
        "Aggregations": [{
            "Name": "avg",
            "Aggregation": {
                "AggName": "agg1",
                "Field": "gid",
                "MissingValue": null
            }
        }]
    }

SDK kullanma

Boolean sorguyu Java SDK, Go SDK, Python SDK, Node.js SDK, .NET SDK veya PHP SDK ile çalıştırabilirsiniz. Bu konuda Java SDK örnek olarak kullanılmıştır.

Aşağıdaki örneklerde Boolean sorgularının nasıl çalıştırılacağı gösterilmektedir.

Tüm alt sorgu koşullarını karşılayan satırları sorgulama

Tüm alt sorgu koşullarını karşılayan satırları sorgularken iş gereksinimlerinize bağlı olarak satırlar için alaka puanlarının hesaplanıp hesaplanmayacağını belirleyebilirsiniz.

Satırlar için alaka puanlarını hesaplama

Aşağıdaki örnek kod, tüm alt sorgu koşullarını karşılayan satırları sorgulamak ve satırlar için alaka puanlarını hesaplamak amacıyla Boolean sorgusunun nasıl çalıştırılacağını göstermektedir.

/**
 * Perform a Boolean query to query the rows that meet all subquery conditions.
 * @param client
 */
public static void andQuery(SyncClient client){
    /**
     * Condition 1: Perform a range query to query the rows in which the value of the Col_Long column is greater than 3.
     */
    RangeQuery rangeQuery = new RangeQuery();
    rangeQuery.setFieldName("Col_Long");
    rangeQuery.greaterThan(ColumnValue.fromLong(3));

    /**
     * Condition 2: Perform a match query to query the rows in which the value of the Col_Keyword column is hangzhou.
     */
    MatchQuery matchQuery = new MatchQuery();
    matchQuery.setFieldName("Col_Keyword");
    matchQuery.setText("hangzhou");

    SearchQuery searchQuery = new SearchQuery();
    {
        /**
         * Construct a Boolean query whose query results meet both Condition 1 and Condition 2.
         */
        BoolQuery boolQuery = new BoolQuery();
        boolQuery.setMustQueries(Arrays.asList(rangeQuery, matchQuery));
        searchQuery.setQuery(boolQuery);
        //searchQuery.setGetTotalCount(true);// Set the GetTotalCount parameter to true to return the total number of rows that meet the query conditions.

        SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
        // You can configure the columnsToGet parameter to specify the columns to return or specify that all columns are returned. If you do not configure this parameter, only the primary key columns are returned.
        //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
        //columnsToGet.setReturnAll(true); // Set the ReturnAll parameter to true to return all columns.
        //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Specify the columns that you want to return.
        //searchRequest.setColumnsToGet(columnsToGet);

        SearchResponse resp = client.search(searchRequest);
        //System.out.println("TotalCount: " + resp.getTotalCount()); // Specify that the total number of rows that meet the query conditions instead of the number of returned rows is displayed.
        System.out.println("Row: " + resp.getRows());
    }
}

Satırlar için alaka puanlarını hesaplamama

Aşağıdaki örnek kod, tüm alt sorgu koşullarını karşılayan satırları sorgulamak ve satırlar için alaka puanlarını hesaplamamak amacıyla Boolean sorgusunun nasıl çalıştırılacağını göstermektedir.

/**
     * Perform a Boolean query to query the rows that meet all subquery conditions without calculating the relevance scores for the rows.
     * @param client
     */
    public static void filtersQuery(SyncClient client){
        /**
         * Condition 1: Perform a range query to query the rows in which the value of the Col_Long column is greater than 3.
         */
        RangeQuery rangeQuery = new RangeQuery();
        rangeQuery.setFieldName("Col_Long");
        rangeQuery.greaterThan(ColumnValue.fromLong(3));

        /**
         * Condition 2: Perform a match query to query the rows in which the value of the Col_Keyword column is hangzhou.
         */
        MatchQuery matchQuery = new MatchQuery();
        matchQuery.setFieldName("Col_Keyword");
        matchQuery.setText("hangzhou");

        SearchQuery searchQuery = new SearchQuery();
        {
            /**
             * Construct a Boolean query whose query results meet both Condition 1 and Condition 2.
             */
            BoolQuery boolQuery = new BoolQuery();
            boolQuery.setFilterQueries(Arrays.asList(rangeQuery, matchQuery));
            searchQuery.setQuery(boolQuery);
            //searchQuery.setGetTotalCount(true);// Set the GetTotalCount parameter to true to return the total number of rows that meet the query conditions.

            SearchRequest searchRequest = new SearchRequest("sampleTable", "sampleSearchIndex", searchQuery);
            // You can configure the columnsToGet parameter to specify the columns to return or specify that all columns are returned. If you do not configure this parameter, only the primary key columns are returned.
            //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
            //columnsToGet.setReturnAll(true); // Set the ReturnAll parameter to true to return all columns.
            //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Specify the columns that you want to return.
            //searchRequest.setColumnsToGet(columnsToGet);

            SearchResponse resp = client.search(searchRequest);
            //System.out.println("TotalCount: " + resp.getTotalCount()); // Specify that the total number of rows that meet the query conditions instead of the number of returned rows is displayed.
            System.out.println("Row: " + resp.getRows());
        }
    }

Alt sorgu koşullarından en az birini karşılayan satırları sorgulama

Aşağıdaki örnek kod, belirtilen alt sorgu koşullarından en az birini karşılayan satırları sorgulamak amacıyla Boolean sorgusunun nasıl çalıştırılacağını göstermektedir:

/**
 * Perform a Boolean query to query the rows that meet at least one of the specified subquery conditions.
 * @param client
 */
public static void orQuery(SyncClient client) {

    /**
     * Condition 1: Perform a range query to query the rows in which the value of the Col_Long column is greater than 3.
     */
    RangeQuery rangeQuery = new RangeQuery();
    rangeQuery.setFieldName("Col_Long");
    rangeQuery.greaterThan(ColumnValue.fromLong(3));

    /**
     * Condition 2: Perform a match query to query the rows in which the value of the Col_Keyword column is hangzhou.
     */
    MatchQuery matchQuery = new MatchQuery();
    matchQuery.setFieldName("Col_Keyword");
    matchQuery.setText("hangzhou");

    SearchQuery searchQuery = new SearchQuery();
    {
    /**
     * Construct a Boolean query whose query results meet at least one of Condition 1 and Condition 2.
     */
    BoolQuery boolQuery = new BoolQuery();
    boolQuery.setShouldQueries(Arrays.asList(rangeQuery, matchQuery));
    boolQuery.setMinimumShouldMatch(1); // Specify that the results meet at least one of the subquery conditions.
    searchQuery.setQuery(boolQuery);
    //searchQuery.setGetTotalCount(true);// Set the GetTotalCount parameter to true to return the total number of rows that meet the query conditions.

    SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
    // You can configure the columnsToGet parameter to specify the columns to return or specify that all columns are returned. If you do not configure this parameter, only the primary key columns are returned.
    //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
    //columnsToGet.setReturnAll(true); // Set the ReturnAll parameter to true to return all columns.
    //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Specify the columns that you want to return.
    //searchRequest.setColumnsToGet(columnsToGet);

    SearchResponse resp = client.search(searchRequest);
    //System.out.println("TotalCount: " + resp.getTotalCount()); // Specify that the total number of rows that meet the query conditions instead of the number of returned rows is displayed.
    System.out.println("Row: " + resp.getRows());
    }
}

Hiçbir alt sorgu koşulunu karşılamayan satırları sorgulama

Aşağıdaki örnek kod, hiçbir alt sorgu koşulunu karşılamayan satırları sorgulamak amacıyla Boolean sorgusunun nasıl çalıştırılacağını göstermektedir:

/**
 * Perform a Boolean query to query the rows that do not meet any subquery conditions.
 * @param client
 */
public static void notQuery(SyncClient client) {

    /**
     * Condition 1: Perform a match query to query the rows in which the value of the Col_Keyword column is hangzhou.
     */
    MatchQuery matchQuery = new MatchQuery();
    matchQuery.setFieldName("Col_Keyword");
    matchQuery.setText("hangzhou");

    SearchQuery searchQuery = new SearchQuery();
    {
        /**
         * Construct a Boolean query whose query results do not meet Condition 1.
         */
        BoolQuery boolQuery = new BoolQuery();
        boolQuery.setMustNotQueries(Arrays.asList(matchQuery));
        searchQuery.setQuery(boolQuery);
        //searchQuery.setGetTotalCount(true);// Set the GetTotalCount parameter to true to return the total number of rows that meet the query conditions.

        SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
        // You can configure the columnsToGet parameter to specify the columns to return or specify that all columns are returned. If you do not configure this parameter, only the primary key columns are returned.
        //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
        //columnsToGet.setReturnAll(true); // Set the ReturnAll parameter to true to return all columns.
        //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Specify the columns that you want to return.
        //searchRequest.setColumnsToGet(columnsToGet);

        SearchResponse resp = client.search(searchRequest);
        //System.out.println("TotalCount: " + resp.getTotalCount()); // Specify that the total number of rows that meet the query conditions instead of the number of returned rows is displayed.
        System.out.println("Row: " + resp.getRows());
    }
}

Alt sorgu koşullarının bir kombinasyonunu karşılayan satırları sorgulama

Aşağıdaki örnek kod, alt sorgu koşullarının bir kombinasyonunu (col2<4 veya col3<5) veya (col2 = 4 ve (col3 = 5 veya col3 =6)) karşılayan satırları sorgulamak amacıyla Boolean sorgusunun nasıl çalıştırılacağını göstermektedir. Yukarıdaki alt sorgu koşulu kombinasyonunda Boolean alt sorguları AND veya OR operatörüyle bağlanır.

/**
 * (col2<4 or col3<5) or (col2 = 4 and (col3 = 5 or col3 =6))
 * The Boolean subqueries are connected by the AND or OR operator.
 * @param client
*/
private static void boolQuery2(SyncClient client){
        // Condition 1: The value of the col2 column is less than 4.
        RangeQuery rangeQuery1 = new RangeQuery();
        rangeQuery1.setFieldName("col2");
        rangeQuery1.lessThan(ColumnValue.fromLong(4));

        // Condition 2: The value of the col3 column is less than 5.
        RangeQuery rangeQuery2 = new RangeQuery();
        rangeQuery2.setFieldName("col3");
        rangeQuery2.lessThan(ColumnValue.fromLong(5));

        // Condition 3: The value of the col2 column is equal to 4.
        TermQuery termQuery = new TermQuery();
        termQuery.setFieldName("col2");
        termQuery.setTerm(ColumnValue.fromLong(4));

        // Condition 4: The value of the col3 column is equal to 5 or the value of the col3 column is equal to 6.
        TermsQuery termsQuery = new TermsQuery();
        termsQuery.setFieldName("col3");
        termsQuery.addTerm(ColumnValue.fromLong(5));
        termsQuery.addTerm(ColumnValue.fromLong(6));

        SearchQuery searchQuery = new SearchQuery();

        List<Query> queryList1 = new ArrayList<>();
        queryList1.add(rangeQuery1);
        queryList1.add(rangeQuery2);

        // Composite condition 1: The value of the col2 column is less than 4 or the value of the col3 column is less than 5.
        BoolQuery boolQuery1 = new BoolQuery();
        boolQuery1.setShouldQueries(queryList1);

        // Composite condition 2: The value of the col2 column is equal to 4 and the value of the col3 column is equal to 5 or 6.
        List<Query> queryList2 = new ArrayList<>();
        queryList2.add(termQuery);
        queryList2.add(termsQuery);

        BoolQuery boolQuery2 = new BoolQuery();
        boolQuery2.setMustQueries(queryList2);

        // Composite conditions: The value of the col2 column is less than 4 or the value of the col3 column is less than 5, or the value of the col2 column is equal to 4 and the value of the col3 column is equal to 5 or 6.

        List<Query> queryList3 = new ArrayList<>();
        queryList3.add(boolQuery1);
        queryList3.add(boolQuery2);

        BoolQuery boolQuery = new BoolQuery();
        boolQuery.setShouldQueries(queryList3);

        searchQuery.setQuery(boolQuery);
        //searchQuery.setGetTotalCount(true);// Set the GetTotalCount parameter to true to return the total number of rows that meet the query conditions.

        SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
        // You can configure the columnsToGet parameter to specify the columns to return or specify that all columns are returned. If you do not configure this parameter, only the primary key columns are returned.
        //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
        //columnsToGet.setReturnAll(true); // Set the ReturnAll parameter to true to return all columns.
        //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Specify the columns that you want to return.
        //searchRequest.setColumnsToGet(columnsToGet);

        SearchResponse response = client.search(searchRequest);
        //System.out.println("TotalCount: " + resp.getTotalCount()); // Specify that the total number of rows that meet the query conditions instead of the number of returned rows is displayed.
        System.out.println(response.getRows());

    }

Faturalandırma

Arama Dizini kullanarak veri sorgulama, okuma aktarım hızını tüketir. Daha fazla bilgi için bkz. Arama Dizini ölçümleme ve faturalandırma.

SSS

Referanslar