

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

# HTML の表形式検索
<a name="searching-tables"></a>

**注記**  
機能のサポートは、使用されているインデックスタイプと検索 API によって異なります。使用しているインデックスタイプと検索 API でこの機能がサポートされているかどうかを確認するには、[インデックスのタイプ](https://docs.aws.amazon.com/kendra/latest/dg/hiw-index-types.html)に関するページを参照してください。

Amazon Kendraの表形式検索機能では、HTML ドキュメントに埋め込まれた表から回答を検索して抽出できます。インデックスを検索すると、クエリに関連する場合、 はテーブルからの抜粋 Amazon Kendra を含め、有用な情報を提供します。

Amazon Kendra は、テーブル内の有用な情報など、ドキュメントの本文テキスト内のすべての情報を確認します。例えば、インデックスには、運用コスト、収入、その他の財務情報に関する表を含むビジネスレポートが含まれています。クエリの場合、「2020-2022 からの年間運用コストはいくらですか？」は、関連するテーブル列「オペレーション (百万 USD)」と「会計年度」、および 2020 年、2021 年、2022 年の収益値を含むテーブル行を含むテーブルの抜粋を返す Amazon Kendra ことができます。結果には、表の抜粋とドキュメントのタイトル、ドキュメント全文へのリンク、選択したドキュメントフィールドが含まれます。

表の抜粋は、情報が表の 1 つのセルにあるか、複数のセルにあるかにかかわらず、検索結果に表示できます。たとえば、 は、これらの種類のクエリごとにカスタマイズされたテーブルの抜粋 Amazon Kendra を表示できます。
+ 「highest interest rate credit card in 2020」
+ 「highest interest rate credit card from 2020-2022」
+ 「top 3 highest interest rate credit cards in 2020-2022」
+ 「credit cards with interest rates less than 10%」
+ 「all available low interest credit cards」

Amazon Kendra は、クエリに最も関連性の高いテーブルセルを強調表示します。最も関連性の高いセルと、それに対応する行、列、列名が検索結果に表示されます。表の抜粋には、クエリに関連する表セルの数と元の表で利用可能な列の数に応じて、最大 5 つの列と 3 つの行が表示されます。表の抜粋では、最も関連性の高いセルが、その次に関連性の高いセルとともに表示されます。

レスポンスには、表の回答がクエリにどの程度関連しているかを示す信頼バケット (`MEDIUM`、`HIGH`、`VERY_HIGH`) が含まれます。表のセルの値の信頼度が `VERY_HIGH` の場合、その値が「最上位の回答」になり、強調表示されます。表のセルの値の信頼度が `HIGH` の場合、その値が強調表示されます。表のセルの値の信頼度が `MEDIUM` の場合、その値は強調表示されません。表の回答に対する全体的な信頼度は、レスポンスで返されます。例えば、表に信頼度 `HIGH` の表のセルのほとんどが含まれている場合、表の回答で返される全体的な信頼度は `HIGH` の信頼度です。

デフォルトでは、表にドキュメントの他の構成要素よりも重要度や重みが付けられることはありません。ドキュメント内で、テーブルがクエリにわずかにしか関連しないが、関連性の高い段落がある場合、 は段落の抜粋 Amazon Kendra を返します。検索結果には、同じドキュメントまたは他のドキュメント内の、最良に近いの回答と最も有用な情報を提供するコンテンツが表示されます。表の信頼度が `MEDIUM` の信頼度を下回ると、そのデーブルの抜粋はレスポンスに返されません。

既存のインデックスで表形式検索を使用するには、コンテンツのインデックスを再作成する必要があります。

Amazon Kendra 表形式検索は[シノニム](https://docs.aws.amazon.com/kendra/latest/dg/index-synonyms.html) (カスタムシノニムを含む) をサポートします。 は、テーブルタグ内の HTML テーブルを含む英語のドキュメント Amazon Kendra のみをサポートします。

次の例は、クエリ結果に含まれる表の抜粋を示しています。表の抜粋を含む、クエリレスポンスを含むサンプル JSON を表示するには、「[Query responses and types](https://docs.aws.amazon.com/kendra/latest/dg/query-responses-types.html)」を参照してください。

------
#### [ Python ]

```
import boto3
import pprint

kendra = boto3.client("kendra")

# Provide the index ID
index_id = <index-id>
# Provide the query text
query = "search string"

response = kendra.query(
        QueryText = query,
        IndexId = index_id)

print("\nSearch results for query: " + query + "\n")        

for query_result in response["ResultItems"]:

    print("-------------------")
    print("Type: " + str(query_result["Type"]))
    print("Type: " + str(query_result["Format"]))
        
    if query_result["Type"]=="ANSWER" and query_result["Format"]=="TABLE":
        answer_table = query_result["TableExcerpt"]
        print(answer_table)
        
    if query_result["Type"]=="ANSWER" and query_result["Format"]=="TEXT":
        answer_text = query_result["DocumentExcerpt"]
        print(answer_text)
        
    if query_result["Type"]=="QUESTION_ANSWER":
        question_answer_text = query_result["DocumentExcerpt"]["Text"]
        print(question_answer_text)

    if query_result["Type"]=="DOCUMENT":
        if "DocumentTitle" in query_result:
            document_title = query_result["DocumentTitle"]["Text"]
            print("Title: " + document_title)
        document_text = query_result["DocumentExcerpt"]["Text"]
        print(document_text)

    print("------------------\n\n")
```

------
#### [ Java ]

```
package com.amazonaws.kendra;

import software.amazon.awssdk.services.kendra.KendraClient;
import software.amazon.awssdk.services.kendra.model.QueryRequest;
import software.amazon.awssdk.services.kendra.model.QueryResponse;
import software.amazon.awssdk.services.kendra.model.QueryResultItem;

public class SearchIndexExample {
    public static void main(String[] args) {
        KendraClient kendra = KendraClient.builder().build();

        String query = "search string";
        String indexId = "index-id";

        QueryRequest queryRequest = QueryRequest
            .builder()
            .queryText(query)
            .indexId(indexId)
            .build();

        QueryResponse queryResponse = kendra.query(queryRequest);

        System.out.println(String.format("\nSearch results for query: %s", query));
        for(QueryResultItem item: queryResponse.resultItems()) {
            System.out.println("----------------------");
            System.out.println(String.format("Type: %s", item.type()));
            System.out.println(String.format("Format: %s", item.format()));
            
            switch(item.format()) {
                case TABLE:
                    String answerTable = item.TableExcerpt();
                    System.out.println(answerTable);
                    break;
            }

            switch(item.format()) {
                case TEXT:
                    String answerText = item.DocumentExcerpt();
                    System.out.println(answerText);
                    break;
            }

            switch(item.type()) {
                case QUESTION_ANSWER:
                    String questionAnswerText = item.documentExcerpt().text();
                    System.out.println(questionAnswerText);
                    break;
                case DOCUMENT:
                    String documentTitle = item.documentTitle().text();
                    System.out.println(String.format("Title: %s", documentTitle));
                    String documentExcerpt = item.documentExcerpt().text();
                    System.out.println(String.format("Excerpt: %s", documentExcerpt));
                    break;
                default:
                    System.out.println(String.format("Unknown query result type: %s", item.type()));

            }

            System.out.println("-----------------------\n");
        }
    }
}
```

------