瀏覽索引 - Amazon Kendra

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

瀏覽索引

注意

功能支援會因索引類型和正在使用的搜尋 API 而有所不同。若要查看索引類型是否支援此功能,並搜尋您正在使用的 API,請參閱索引類型

您可以依文件的屬性或面向瀏覽文件,而不必輸入搜尋查詢。 Amazon Kendra 索引瀏覽可以透過自由瀏覽索引來協助您的使用者探索文件,而不需要考慮特定的查詢。這也可協助您的使用者廣泛瀏覽索引,做為搜尋的起點。

索引瀏覽只能用於依具有排序類型的文件屬性或構面進行搜尋。您無法使用索引瀏覽搜尋整個索引。如果查詢文字遺失,則 Amazon Kendra 會要求文件屬性篩選條件或構面,以及排序類型。

若要允許使用查詢API瀏覽索引,您必須包含 AttributeFilter 面向,以及 SortingConfiguration。若要允許在 主控台中瀏覽索引,請在導覽功能表中的索引下選取您的索引,然後選取搜尋索引的選項。在搜尋方塊中,按 Enter 鍵兩次。選取下拉式清單篩選條件搜尋結果以選擇篩選條件,然後選取下拉式清單排序以選擇排序類型。

以下是以西班牙文語言瀏覽文件索引的範例,依文件建立日期的遞減順序排列。

CLI
aws kendra query \ --index-id "index-id" \ --attribute-filter '{ "EqualsTo":{ "Key": "_language_code", "Value": { "StringValue": "es" } } }' \ --sorting-configuration '{ "DocumentAttributeKey": "_created_at", "SortOrder": "DESC" }'
Python
import boto3 kendra = boto3.client("kendra") # Must include the index ID, the attribute filter, and sorting configuration response = kendra.query( IndexId = "index-id", AttributeFilter = { "EqualsTo": { "Key": "_language_code", "Value": { "StringValue": "es" } } }, SortingConfiguration = { "DocumentAttributeKey": "_created_at", "SortOrder": "DESC"}) print("\nSearch results|Resultados de la búsqueda: \n") for query_result in response["ResultItems"]: print("-------------------") print("Type: " + str(query_result["Type"])) if query_result["Type"]=="ANSWER" or query_result["Type"]=="QUESTION_ANSWER": answer_text = query_result["DocumentExcerpt"]["Text"] print(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.QueryResult; import software.amazon.awssdk.services.kendra.model.QueryResultItem; public class SearchIndexExample { public static void main(String[] args) { KendraClient kendra = KendraClient.builder().build(); QueryRequest queryRequest = QueryRequest.builder() .withIndexId("index-id") .withAttributeFilter(AttributeFilter.builder() .withEqualsTo(DocumentAttribute.builder() .withKey("_language_code") .withValue(DocumentAttributeValue.builder() .withStringValue("es") .build()) .build()) .build()) .withSortingConfiguration(SortingConfiguration.builder() .withDocumentAttributeKey("_created_at") .withSortOrder("DESC") .build()) .build()); QueryResult queryResult = kendra.query(queryRequest); for (QueryResultItem item : queryResult.getResultItems()) { System.out.println("----------------------"); System.out.println(String.format("Type: %s", item.getType())); switch (item.getType()) { case QueryResultType.QUESTION_ANSWER: case QueryResultType.ANSWER: String answerText = item.getDocumentExcerpt().getText(); System.out.println(answerText); break; case QueryResultType.DOCUMENT: String documentTitle = item.getDocumentTitle().getText(); System.out.println(String.format("Title: %s", documentTitle)); String documentExcerpt = item.getDocumentExcerpt().getText(); System.out.println(String.format("Excerpt: %s", documentExcerpt)); break; default: System.out.println(String.format("Unknown query result type: %s", item.getType())); } System.out.println("-----------------------\n"); } } }