Tüm Ürünler
Search
Belge Merkezi

Tablestore:İç içe geçmiş sorgu

Son Güncelleme:Oct 02, 2026

İç içe geçmiş alanların alt satırlarındaki verileri sorgulamak için iç içe geçmiş sorgu yapabilirsiniz. İç içe geçmiş alanlar doğrudan sorgulanamaz. Bir iç içe geçmiş alanı sorgulamak için NestedQuery nesnesinde iç içe geçmiş alanın yolunu ve bir alt sorgu belirtmeniz gerekir. Alt sorgu herhangi bir türde olabilir.

Önemli
  • Yalnızca iç içe geçmiş alanlar iç içe geçmiş sorgularla sorgulanabilir.

  • Tek bir istekte hem iç içe geçmiş alanlarda hem de diğer türdeki alanlarda sorgulama yapabilirsiniz. İç içe geçmiş alan türü hakkında daha fazla bilgi için bkz. Nested data type.

API işlemi

İç içe geçmiş bir sorgu yapmak için Search veya ParallelScan işlemini çağırabilir ve sorgu türünü NestedQuery olarak ayarlayabilirsiniz.

Parametreler

Parametre

Açıklama

path

İç içe geçmiş alanın yolu. Yol, ağaç yapısına benzer. Örneğin, news.title ifadesi news adlı iç içe geçmiş alandaki title alt alanını belirtir.

query

İç içe geçmiş alandaki alt alanda yapmak istediğiniz sorgu. Sorgu herhangi bir sorgu türünde olabilir.

scoreMode

Bir alan birden çok değer içeriyorsa puanı hesaplamak için kullanılan değer.

getTotalCount

Sorgu koşullarını karşılayan toplam satır sayısının döndürülüp döndürülmeyeceğini belirtir. Bu parametrenin varsayılan değeri false olup, sorgu koşullarını karşılayan toplam satır sayısının döndürülmediğini belirtir.

Bu parametreyi true olarak ayarlarsanız sorgu performansı düşer.

weight

BM25 tabanlı anahtar sözcük alakalı skorunu hesaplamak için sorgulamak istediğiniz alana atamak istediğiniz ağırlık. Bu parametre tam metin arama senaryolarında kullanılır. Daha yüksek bir ağırlık, alan için daha yüksek BM25 tabanlı anahtar sözcük alakalı skoru ile sonuçlanır. Bu parametrenin değeri pozitif bir kayan noktalı sayıdır.

Bu parametre döndürülen satır sayısını etkilemez. Ancak bu parametre, sorgu sonuçlarının BM25 tabanlı anahtar sözcük alakalı skorlarını etkiler.

tableName

Veri tablosunun adı.

indexName

Arama dizininin adı.

columnsToGet

Sorgu koşullarını karşılayan her satırın tüm sütunlarının döndürülüp döndürülmeyeceğini belirtir. Bu parametre için returnAll ve columns parametrelerini yapılandırabilirsiniz.

returnAll parametresinin varsayılan değeri false olup, tüm sütunların döndürülmediğini belirtir. Bu durumda, döndürmek istediğiniz sütunları belirtmek için columns parametresini kullanabilirsiniz. Döndürmek istediğiniz sütunları belirtmezseniz yalnızca birincil anahtar sütunları döndürülür.

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

InnerHits

İç içe geçmiş alanın alt alanlarının ayarları.

  • sort: iç içe geçmiş alanın alt satırları için sıralama kuralı.

  • offset: iç içe geçmiş alan birden çok alt satırdan oluşuyorsa döndürülecek alt satırların başlangıç konumu.

  • limit: iç içe geçmiş alan birden çok alt satırdan oluşuyorsa döndürülecek maksimum alt satır sayısı. Varsayılan değer: 3.

  • highlight: iç içe geçmiş alanın alt alanları için vurgulama ayarları. Daha fazla bilgi için bkz. Highlight.

Yöntemler

İç içe geçmiş bir sorgu yapmak için Tablestore konsolunu veya Tablestore SDK'larını kullanabilirsiniz. İç içe geçmiş bir sorgu yapmadan önce aşağıdaki hazırlıkları yaptığınızdan emin olun:

  • Tablestore işlem izinlerine sahip bir Alibaba Cloud hesabı veya RAM kullanıcısı oluşturun. Bir RAM kullanıcısına Tablestore işlem izinleri verme hakkında bilgi için bkz. Use a RAM policy to grant permissions to a RAM user.

    İç içe geçmiş bir sorgu yapmak için Tablestore SDK'larını kullanmak istiyorsanız Alibaba Cloud hesabınız veya RAM kullanıcınız için bir AccessKey çifti oluşturun. Daha fazla bilgi için bkz. Create an AccessKey pair.

    Uyarı

    Bir Alibaba Cloud hesabının AccessKey çifti tüm API işlemleri üzerinde izinlere sahiptir. API işlemlerini çağırmak veya rutin işletim ve bakım görevlerini yapmak için bir RAM kullanıcısı kullanmanızı öneririz. AccessKey ID'sini ve AccessKey gizli anahtarını proje kodunuzda sabit kodlamamanızı öneririz. Aksi takdirde AccessKey çifti sızdırılabilir ve hesabınızdaki tüm kaynakların güvenliği tehlikeye girebilir.

  • Bir veri tablosu oluşturun. Daha fazla bilgi için bkz. Operations on a data table.

  • Veri tablosu için bir arama dizini oluşturun. Daha fazla bilgi için bkz. Create a search index.

  • İç içe geçmiş bir sorgu yapmak için Tablestore SDK'larını kullanmak istiyorsanız bir OTSClient örneği başlatın. Daha fazla bilgi için bkz. Initialize an OTSClient instance.

Tablestore konsolunu kullanma

İç içe geçmiş bir sorgu yaparken Tablestore konsolunu kullanarak yalnızca tek düzeyli iç içe geçmiş alanların verilerini sorgulayabilirsiniz.

  1. Index Management sekmesine gidin.

    1. Table Store konsolu adresine gidip oturum açın.

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

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

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

  2. Index Management sekmesinde hedef Arama Dizini bulun ve Actions sütununda Search seçeneğine tıklayın.

  3. Search iletişim kutusunda verileri sorgulayın.

    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 ayrılmış sütun adlarını girin.

      Not

      Varsayılan olarak Table Store, 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şulu karşılamayan verileri döndürür.

    3. İç içe geçmiş türde bir alan seçin ve Add seçeneğine tıklayın.

    4. Bir alt alan seçin, sorgu türünü istediğiniz türe (örneğin TermQuery) ayarlayın ve sorgulamak için bir değer girin.

    5. Varsayılan olarak sıralama devre dışı bırakılı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.

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

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

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

Tablestore SDK'larını kullanma

Tek düzeyli ve çok düzeyli iç içe geçmiş tür alanlardaki verileri sorgulamak için bir SDK kullanabilirsiniz. İç içe geçmiş bir sorgu yaparken sonuçlardaki anahtar sözcükleri vurgulamak için vurgulama özelliğini kullanabilirsiniz. Vurgulama hakkında daha fazla bilgi için bkz. vurgulama.

İç içe geçmiş bir sorgu yapmak için aşağıdaki Tablestore SDK'larını kullanabilirsiniz: Java için Tablestore SDK'sı, Go için Tablestore SDK'sı, Python için Tablestore SDK'sı, Node.js için Tablestore SDK'sı, .NET için Tablestore SDK'sı ve PHP için Tablestore SDK'sı. Bu örnekte Java için Tablestore SDK'sı kullanılmaktadır.

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

Aşağıdaki örnekte col_nested.nested_1 değeri tablestore olan verilerin nasıl sorgulanacağı gösterilmektedir. Bu örnekte col_nested, alt satırları nested_1 ve nested_2 sütunlarını içeren iç içe geçmiş bir alandır.

private static void nestedQuery(SyncClient client) {
    SearchQuery searchQuery = new SearchQuery();
    NestedQuery nestedQuery = new NestedQuery(); // Set the query type to NestedQuery.
    nestedQuery.setPath("col_nested"); // Set the path of the nested column.
    TermQuery termQuery = new TermQuery(); // Construct the subquery for NestedQuery.
    termQuery.setFieldName("col_nested.nested_1"); // Set the column name. Note that it includes the path of the nested column.
    termQuery.setTerm(ColumnValue.fromString("tablestore")); // Set the value to query.
    nestedQuery.setQuery(termQuery);
    nestedQuery.setScoreMode(ScoreMode.None);
    searchQuery.setQuery(nestedQuery);
    //searchQuery.setGetTotalCount(true); // Set this to return the total number of matched rows.

    SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
    // Use the columnsToGet parameter to specify the columns to return or to return all columns. If you do not set this parameter, only the primary key columns are returned by default.
    //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
    //columnsToGet.setReturnAll(true); // Set this to return all columns.
    //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Set this to return specified columns.
    //searchRequest.setColumnsToGet(columnsToGet);

    SearchResponse resp = client.search(searchRequest);
    //System.out.println("TotalCount: " + resp.getTotalCount()); // Print the total number of matched rows, not the number of returned rows.
    System.out.println("Row: " + resp.getRows());
}

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

Aşağıdaki örnekte col_nested.nested_2.nested_2_2 değeri tablestore olan verilerin nasıl sorgulanacağı gösterilmektedir. Bu örnekte col_nested, alt satırları nested_1 ve nested_2 sütunlarını içeren iç içe geçmiş bir alandır. nested_2 sütunu da alt satırları nested_2_1 ve nested_2_2 sütunlarını içeren iç içe geçmiş bir alandır.

private static void nestedQuery(SyncClient client) {
    SearchQuery searchQuery = new SearchQuery();
    NestedQuery nestedQuery = new NestedQuery(); // Set the query type to NestedQuery.
    nestedQuery.setPath("col_nested.nested_2"); // Set the path of the nested column, which is the parent path of the field to query.
    TermQuery termQuery = new TermQuery(); // Construct the subquery for NestedQuery.
    termQuery.setFieldName("col_nested.nested_2.nested_2_2"); // Set the column name, which is the full path of the field to query.
    termQuery.setTerm(ColumnValue.fromString("tablestore")); // Set the value to query.
    nestedQuery.setQuery(termQuery);
    nestedQuery.setScoreMode(ScoreMode.None);
    searchQuery.setQuery(nestedQuery);
    //searchQuery.setGetTotalCount(true); // Set this to return the total number of matched rows.

    SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
    // Use the columnsToGet parameter to specify the columns to return or to return all columns. If you do not set this parameter, only the primary key columns are returned by default.
    //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
    //columnsToGet.setReturnAll(true); // Set this to return all columns.
    //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Set this to return specified columns.
    //searchRequest.setColumnsToGet(columnsToGet);

    SearchResponse resp = client.search(searchRequest);
    //System.out.println("TotalCount: " + resp.getTotalCount()); // Print the total number of matched rows, not the number of returned rows.
    System.out.println("Row: " + resp.getRows());
}

Bileşik iç içe geçmiş sorgu örneği

Sorgu gereksinimleri

Bir veri tablosunda col_string (String) ve col_nested (String) olmak üzere iki sütun olduğunu varsayalım. col_nested sütunu JSON formatında veri depolar. Aşağıdaki tabloda bu veri tablosundan örnek veriler gösterilmektedir.

Not

Her satıra gösterim amaçlı bir satır numarası sütunu eklenmiştir.


Satır numarası


col_string


col_nested


1


a


[{"col_keyword": "tablestore"},{"col_keyword": "searchindex","col_long": 1}]


2


b


[{"col_keyword": "tablestore","col_long": 1}]


3


c


[{"col_keyword": "searchindex"},{"col_long": 1}]

col_nested sütunundaki veriler için aşağıdaki sorgu gereksinimleriniz olduğunu varsayalım:

  • Tek bir alt satır birden çok sorgu koşulunu karşılar

    Örneğin, col_nested sütunundaki tek bir alt satırın aşağıdaki iki koşulu da karşıladığı satırları sorgulayabilirsiniz: col_keyword sütununun değeri tablestore ve col_long sütununun değeri boş değil.

  • Farklı alt satırlar birden çok sorgu koşulunu karşılar

    Örneğin, col_nested sütunundaki bir alt satırın col_keyword değerinin tablestore olduğu ve başka bir alt satırın col_long değerinin boş olmadığı satırları sorgulayabilirsiniz.

Bu sorgu gereksinimlerini karşılamak için aşağıdaki adımları uygulayabilirsiniz:

  1. Veri tablosu için bir arama dizini oluşturun ve arama dizininde col_nested sütununu iç içe geçmiş tür olarak ayarlayın.

    col_nested sütunu iki alt alan içerir: col_keyword (Anahtar Sözcük) ve col_long (Uzun).

  2. Gereksinimlerinize göre uygun sorgu yöntemini kullanın.

    • Tek bir alt satırın birden çok sorgu koşulunu karşıladığı bir sorgu yapmak için NestedQuery içinde birden çok BoolQuery yapılandırın.

    • Birden çok koşulu karşılayan farklı alt satırları sorgulamak için bir BoolQuery altında birden çok NestedQuery koşulu ayarlayabilirsiniz.

Aşağıdaki örneklerde verilerin nasıl sorgulanacağı gösterilmektedir. Sorgu gereksinimlerinize uyan örneğe bakabilirsiniz.

Tek bir alt satırın birden çok koşulu karşıladığı sorgu örneği

Aşağıdaki örnekte col_nested sütunundaki tek bir alt satırın şu iki koşulu da karşıladığı satırların nasıl sorgulanacağı gösterilmektedir: `col_nested.col_keyword değeri "tablestore" ve `col_nested.col_long değeri boş değil.

Örnek verilere göre yalnızca 2. satırdaki veriler sorgu koşullarını karşılar.

public static void nestedQuery(SyncClient client) {
    // Condition 1: The value of the col_keyword column in the child row of col_nested must be "tablestore".
    TermQuery termQuery = new TermQuery();
    termQuery.setFieldName("col_nested.col_keyword");
    termQuery.setTerm(ColumnValue.fromString("tablestore"));

    // Condition 2: The col_long column in the child row of col_nested must not be empty.
    ExistsQuery existsQuery = new ExistsQuery();
    existsQuery.setFieldName("col_nested.col_long");

    // Use the AND condition of BoolQuery to query for child rows that meet both conditions.
    List<Query> mustQueries = new ArrayList<>();
    mustQueries.add(termQuery);
    mustQueries.add(existsQuery);
    BoolQuery boolQuery = new BoolQuery();
    boolQuery.setMustQueries(mustQueries);

    // Set a BoolQuery within the NestedQuery to require a child row to meet multiple query conditions at the same time.
    NestedQuery nestedQuery = new NestedQuery();    // Set the query type to NestedQuery.
    nestedQuery.setPath("col_nested");   // Set the path of the nested column, which is the parent path of the field to query.
    nestedQuery.setQuery(boolQuery);
    nestedQuery.setScoreMode(ScoreMode.None);

    SearchQuery searchQuery = new SearchQuery();
    searchQuery.setQuery(nestedQuery);

    SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
    // Use the columnsToGet parameter to specify the columns to return or to return all columns. If you do not set this parameter, only the primary key columns are returned by default.
    //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
    //columnsToGet.setReturnAll(true); // Set this to return all columns.
    //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Set this to return specified columns.
    //searchRequest.setColumnsToGet(columnsToGet);

    SearchResponse resp = client.search(searchRequest);
    //System.out.println("TotalCount: " + resp.getTotalCount()); // Print the total number of matched rows, not the number of returned rows.
    System.out.println("Row: " + resp.getRows());
}

Farklı alt satırların birden çok koşulu karşıladığı sorgu örneği

Aşağıdaki örnekte col_nested alanındaki iç içe geçmiş nesnelerin iki koşulu karşıladığı satırlar sorgulanmaktadır: col_nested.col_keyword değeri "tablestore" ve col_nested.col_long değeri boş değil.

Örnek verilere göre 1. ve 2. satırdaki veriler sorgu koşullarını karşılar.

public static void nestedQuery(SyncClient client) {
        // Condition 1: The value of the col_keyword column in the child row of col_nested must be "tablestore".
        TermQuery termQuery = new TermQuery();
        termQuery.setFieldName("col_nested.col_keyword");
        termQuery.setTerm(ColumnValue.fromString("tablestore"));
        NestedQuery nestedTermQuery = new NestedQuery();
        nestedTermQuery.setPath("col_nested");
        nestedTermQuery.setScoreMode(ScoreMode.None);
        nestedTermQuery.setQuery(termQuery);

        // Condition 2: The col_long column in the child row of col_nested must not be empty.
        ExistsQuery existsQuery = new ExistsQuery();
        existsQuery.setFieldName("col_nested.col_long");
        NestedQuery nestedExistsQuery = new NestedQuery();
        nestedExistsQuery.setPath("col_nested");
        nestedExistsQuery.setScoreMode(ScoreMode.None);
        nestedExistsQuery.setQuery(existsQuery);

        // Use the AND condition of BoolQuery to query for rows that meet the preceding conditions.
        List<Query> mustQueries = new ArrayList<>();
        mustQueries.add(nestedTermQuery);
        mustQueries.add(nestedExistsQuery);

        // The BoolQuery includes multiple NestedQuery conditions. The query is successful if different child rows meet the respective query conditions.
        BoolQuery boolQuery = new BoolQuery();
        boolQuery.setMustQueries(mustQueries);

        SearchQuery searchQuery = new SearchQuery();
        searchQuery.setQuery(boolQuery);

        SearchRequest searchRequest = new SearchRequest("<TABLE_NAME>", "<SEARCH_INDEX_NAME>", searchQuery);
        // Use the columnsToGet parameter to specify the columns to return or to return all columns. If you do not set this parameter, only the primary key columns are returned by default.
        //SearchRequest.ColumnsToGet columnsToGet = new SearchRequest.ColumnsToGet();
        //columnsToGet.setReturnAll(true); // Set this to return all columns.
        //columnsToGet.setColumns(Arrays.asList("ColName1","ColName2")); // Set this to return specified columns.
        //searchRequest.setColumnsToGet(columnsToGet);

        SearchResponse resp = client.search(searchRequest);
        //System.out.println("TotalCount: " + resp.getTotalCount()); // Print the total number of matched rows, not the number of returned rows.
        System.out.println("Row: " + resp.getRows());
    }

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

Aşağıdaki örnekte Col_Nested iç içe geçmiş alanındaki Level1_Col1_Nested alt alanının değeri `hangzhou shanghai ile eşleşen verileri sorgulamak için NestedQuery kullanılması gösterilmektedir. Arama sorgusu döndürülen sonuçlarda vurgulanır.

/**
 * Use summary and highlighting in a NestedQuery. Set parameters using innerHits.
 */
public static void nestedQueryWithHighlighting(SyncClient client) {
        SearchRequest searchRequest = SearchRequest.newBuilder()
                .tableName("<TABLE_NAME>")
                .indexName("<SEARCH_INDEX_NAME>")
                .returnAllColumnsFromIndex(true)
                .searchQuery(SearchQuery.newBuilder()
                        .limit(5)
                        .query(QueryBuilders.nested()
                                .path("Col_Nested")
                                .scoreMode(ScoreMode.Min)
                                .query(QueryBuilders.match("Col_Nested.Level1_Col1_Nested", "hangzhou shanghai"))
                                .innerHits(InnerHits.newBuilder()
                                        .highlight(Highlight.newBuilder()
                                                .addFieldHighlightParam("Col_Nested.Level1_Col1_Nested", HighlightParameter.newBuilder().build())
                                                .build())
                                        .build()))
                        .build())
                .build();
        SearchResponse resp = client.search(searchRequest);

        // Print the highlighted results.
        printSearchHit(resp.getSearchHits(), "");
}

/**
 * Print the content of searchHit.
 * @param searchHits The search hits.
 * @param prefix The prefix to add when printing nested structures to show hierarchical information.
 */
private static void printSearchHit(List<SearchHit> searchHits, String prefix) {
    for (SearchHit searchHit : searchHits) {
        if (searchHit.getScore() != null) {
            System.out.printf("%s Score: %s\n", prefix, searchHit.getScore());
        }

        if (searchHit.getOffset() != null) {
            System.out.printf("%s Offset: %s\n", prefix, searchHit.getOffset());
        }

        if (searchHit.getRow() != null) {
            System.out.printf("%s Row: %s\n", prefix, searchHit.getRow().toString());
        }

        // Print the highlighted fragments for each field.
        if (searchHit.getHighlightResultItem() != null) {
            System.out.printf("%s Highlight: \n", prefix);
            StringBuilder strBuilder = new StringBuilder();
            for (Map.Entry<String, HighlightField> entry : searchHit.getHighlightResultItem().getHighlightFields().entrySet()) {
                strBuilder.append(entry.getKey()).append(":").append("[");
                strBuilder.append(StringUtils.join(",", entry.getValue().getFragments())).append("]\n");
            }
            System.out.printf("%s   %s", prefix, strBuilder);
        }

        // Highlighted results for the nested type.
        for (SearchInnerHit searchInnerHit : searchHit.getSearchInnerHits().values()) {
            System.out.printf("%s Path: %s\n", prefix, searchInnerHit.getPath());
            System.out.printf("%s InnerHit: \n", prefix);
            printSearchHit(searchInnerHit.getSubSearchHits(), prefix + "    ");
        }

        System.out.println();
    }
}

Çok düzeyli iç içe geçmiş alan Col_Nested'in iki alt alan içerdiğini varsayalım: Level1_Col1_Text (Metin) ve Level1_Col2_Nested (İç İçe Geçmiş). Level1_Col2_Nested iç içe geçmiş alanı Level2_Col1_Text alt alanını içerir.

Aşağıdaki örnekte hem Col_Nested alanındaki Level1_Col1_Text alt alanında hem de Level1_Col2_Nested altındaki Level2_Col1_Text alt alanında özet ve vurgulama özelliklerini kullanmak için bir NestedQuery içine BoolQuery eklenmesi gösterilmektedir.

public static void nestedQueryWithHighlighting(SyncClient client) {
    SearchRequest searchRequest = SearchRequest.newBuilder()
            .tableName("<TABLE_NAME>")
            .indexName("<SEARCH_INDEX_NAME>")
            .returnAllColumnsFromIndex(true)
            .searchQuery(SearchQuery.newBuilder()
                    .limit(5)
                    .query(QueryBuilders.nested()
                            .path("Col_Nested")
                            .scoreMode(ScoreMode.Min)
                            .query(QueryBuilders.bool()
                                    .should(QueryBuilders.match("Col_Nested.Level1_Col1_Text", "hangzhou shanghai"))
                                    .should(QueryBuilders.nested()
                                            .path("Col_Nested.Level1_Col2_Nested")
                                            .scoreMode(ScoreMode.Min)
                                            .query(QueryBuilders.match("Col_Nested.Level1_Col2_Nested.Level2_Col1_Text", "hangzhou shanghai"))
                                            .innerHits(InnerHits.newBuilder()
                                                    .highlight(Highlight.newBuilder()
                                                            .addFieldHighlightParam("Col_Nested.Level1_Col2_Nested.Level2_Col1_Text", HighlightParameter.newBuilder().build())
                                                            .build())
                                                    .build())))
                            .innerHits(InnerHits.newBuilder()
                                    .sort(new Sort(Arrays.asList(
                                            new ScoreSort(),
                                            new DocSort()
                                    )))
                                    .highlight(Highlight.newBuilder()
                                            .addFieldHighlightParam("Col_Nested.Level1_Col1_Text", HighlightParameter.newBuilder().build())
                                            .build())
                                    .build()))
                    .build())
            .build();
    SearchResponse resp = client.search(searchRequest);
    // Print the highlighted results.
    printSearchHit(resp.getSearchHits(), "");
}

/**
 * Print the content of searchHit.
 * @param searchHits The search hits.
 * @param prefix The prefix to add when printing nested structures to show hierarchical information.
 */
private static void printSearchHit(List<SearchHit> searchHits, String prefix) {
    for (SearchHit searchHit : searchHits) {
        if (searchHit.getScore() != null) {
            System.out.printf("%s Score: %s\n", prefix, searchHit.getScore());
        }

        if (searchHit.getOffset() != null) {
            System.out.printf("%s Offset: %s\n", prefix, searchHit.getOffset());
        }

        if (searchHit.getRow() != null) {
            System.out.printf("%s Row: %s\n", prefix, searchHit.getRow().toString());
        }

        // Print the highlighted fragments for each field.
        if (searchHit.getHighlightResultItem() != null) {
            System.out.printf("%s Highlight: \n", prefix);
            StringBuilder strBuilder = new StringBuilder();
            for (Map.Entry<String, HighlightField> entry : searchHit.getHighlightResultItem().getHighlightFields().entrySet()) {
                strBuilder.append(entry.getKey()).append(":").append("[");
                strBuilder.append(StringUtils.join(",", entry.getValue().getFragments())).append("]\n");
            }
            System.out.printf("%s   %s", prefix, strBuilder);
        }

        // Highlighted results for the nested type.
        for (SearchInnerHit searchInnerHit : searchHit.getSearchInnerHits().values()) {
            System.out.printf("%s Path: %s\n", prefix, searchInnerHit.getPath());
            System.out.printf("%s InnerHit: \n", prefix);
            printSearchHit(searchInnerHit.getSubSearchHits(), prefix + "    ");
        }

        System.out.println();
    }
}

Faturalama

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

SSS

Referanslar