getQuerySuggestions method
Fetches the queries that are suggested to your users.
GetQuerySuggestions is currently not supported in the Amazon
Web Services GovCloud (US-West) region.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ServiceQuotaExceededException.
May throw ThrottlingException.
May throw ValidationException.
Parameter indexId :
The identifier of the index you want to get query suggestions from.
Parameter queryText :
The text of a user's query to generate query suggestions.
A query is suggested if the query prefix matches what a user starts to type as their query.
Amazon Kendra does not show any suggestions if a user types fewer than two characters or more than 60 characters. A query must also have at least one search result and contain at least one word of more than four characters.
Parameter attributeSuggestionsConfig :
Configuration information for the document fields/attributes that you want
to base query suggestions on.
Parameter maxSuggestionsCount :
The maximum number of query suggestions you want to show to your users.
Parameter suggestionTypes :
The suggestions type to base query suggestions on. The suggestion types
are query history or document fields/attributes. You can set one type or
the other.
If you set query history as your suggestions type, Amazon Kendra suggests queries relevant to your users based on popular queries in the query history.
If you set document fields/attributes as your suggestions type, Amazon Kendra suggests queries relevant to your users based on the contents of document fields.
Implementation
Future<GetQuerySuggestionsResponse> getQuerySuggestions({
required String indexId,
required String queryText,
AttributeSuggestionsGetConfig? attributeSuggestionsConfig,
int? maxSuggestionsCount,
List<SuggestionType>? suggestionTypes,
}) async {
final headers = <String, String>{
'Content-Type': 'application/x-amz-json-1.1',
'X-Amz-Target': 'AWSKendraFrontendService.GetQuerySuggestions'
};
final jsonResponse = await _protocol.send(
method: 'POST',
requestUri: '/',
exceptionFnMap: _exceptionFns,
// TODO queryParams
headers: headers,
payload: {
'IndexId': indexId,
'QueryText': queryText,
if (attributeSuggestionsConfig != null)
'AttributeSuggestionsConfig': attributeSuggestionsConfig,
if (maxSuggestionsCount != null)
'MaxSuggestionsCount': maxSuggestionsCount,
if (suggestionTypes != null)
'SuggestionTypes': suggestionTypes.map((e) => e.value).toList(),
},
);
return GetQuerySuggestionsResponse.fromJson(jsonResponse.body);
}