kendra / Client / get_query_suggestions

get_query_suggestions#

kendra.Client.get_query_suggestions(**kwargs)#

Fetches the queries that are suggested to your users.

GetQuerySuggestions is currently not supported in the Amazon Web Services GovCloud (US-West) region.

See also: AWS API Documentation

Request Syntax

response = client.get_query_suggestions(
    IndexId='string',
    QueryText='string',
    MaxSuggestionsCount=123,
    SuggestionTypes=[
        'QUERY'|'DOCUMENT_ATTRIBUTES',
    ],
    AttributeSuggestionsConfig={
        'SuggestionAttributes': [
            'string',
        ],
        'AdditionalResponseAttributes': [
            'string',
        ],
        'AttributeFilter': {
            'AndAllFilters': [
                {'... recursive ...'},
            ],
            'OrAllFilters': [
                {'... recursive ...'},
            ],
            'NotFilter': {'... recursive ...'},
            'EqualsTo': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'ContainsAll': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'ContainsAny': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'GreaterThan': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'GreaterThanOrEquals': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'LessThan': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            },
            'LessThanOrEquals': {
                'Key': 'string',
                'Value': {
                    'StringValue': 'string',
                    'StringListValue': [
                        'string',
                    ],
                    'LongValue': 123,
                    'DateValue': datetime(2015, 1, 1)
                }
            }
        },
        'UserContext': {
            'Token': 'string',
            'UserId': 'string',
            'Groups': [
                'string',
            ],
            'DataSourceGroups': [
                {
                    'GroupId': 'string',
                    'DataSourceId': 'string'
                },
            ]
        }
    }
)
Parameters:
  • IndexId (string) –

    [REQUIRED]

    The identifier of the index you want to get query suggestions from.

  • QueryText (string) –

    [REQUIRED]

    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.

  • MaxSuggestionsCount (integer) – The maximum number of query suggestions you want to show to your users.

  • SuggestionTypes (list) –

    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.

    • (string) –

  • AttributeSuggestionsConfig (dict) –

    Configuration information for the document fields/attributes that you want to base query suggestions on.

    • SuggestionAttributes (list) –

      The list of document field/attribute keys or field names to use for query suggestions. If the content within any of the fields match what your user starts typing as their query, then the field content is returned as a query suggestion.

      • (string) –

    • AdditionalResponseAttributes (list) –

      The list of additional document field/attribute keys or field names to include in the response. You can use additional fields to provide extra information in the response. Additional fields are not used to based suggestions on.

      • (string) –

    • AttributeFilter (dict) –

      Filters the search results based on document fields/attributes.

      • AndAllFilters (list) –

        Performs a logical AND operation on all supplied filters.

        • (dict) –

          Provides filtering the query results based on document attributes or metadata fields.

          When you use the AndAllFilters or OrAllFilters, filters you can use 2 layers under the first attribute filter. For example, you can use:

          <AndAllFilters>

          • <OrAllFilters>

          • <EqualsTo>

          If you use more than 2 layers, you receive a ValidationException exception with the message “ AttributeFilter cannot have a depth of more than 2.”

          If you use more than 10 attribute filters in a given list for AndAllFilters or OrAllFilters, you receive a ValidationException with the message “ AttributeFilter cannot have a length of more than 10”.

      • OrAllFilters (list) –

        Performs a logical OR operation on all supplied filters.

        • (dict) –

          Provides filtering the query results based on document attributes or metadata fields.

          When you use the AndAllFilters or OrAllFilters, filters you can use 2 layers under the first attribute filter. For example, you can use:

          <AndAllFilters>

          • <OrAllFilters>

          • <EqualsTo>

          If you use more than 2 layers, you receive a ValidationException exception with the message “ AttributeFilter cannot have a depth of more than 2.”

          If you use more than 10 attribute filters in a given list for AndAllFilters or OrAllFilters, you receive a ValidationException with the message “ AttributeFilter cannot have a length of more than 10”.

      • NotFilter (dict) –

        Performs a logical NOT operation on all supplied filters.

      • EqualsTo (dict) –

        Performs an equals operation on two document attributes or metadata fields.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • ContainsAll (dict) –

        Returns true when a document contains all of the specified document attributes or metadata fields. This filter is only applicable to StringListValue metadata.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • ContainsAny (dict) –

        Returns true when a document contains any of the specified document attributes or metadata fields. This filter is only applicable to StringListValue metadata.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • GreaterThan (dict) –

        Performs a greater than operation on two document attributes or metadata fields. Use with a document attribute of type Date or Long.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • GreaterThanOrEquals (dict) –

        Performs a greater or equals than operation on two document attributes or metadata fields. Use with a document attribute of type Date or Long.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • LessThan (dict) –

        Performs a less than operation on two document attributes or metadata fields. Use with a document attribute of type Date or Long.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

      • LessThanOrEquals (dict) –

        Performs a less than or equals operation on two document attributes or metadata fields. Use with a document attribute of type Date or Long.

        • Key (string) – [REQUIRED]

          The identifier for the attribute.

        • Value (dict) – [REQUIRED]

          The value of the attribute.

          • StringValue (string) –

            A string, such as “department”.

          • StringListValue (list) –

            A list of strings. The default maximum length or number of strings is 10.

            • (string) –

          • LongValue (integer) –

            A long integer value.

          • DateValue (datetime) –

            A date expressed as an ISO 8601 string.

            It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

    • UserContext (dict) –

      Applies user context filtering so that only users who are given access to certain documents see these document in their search results.

      • Token (string) –

        The user context token for filtering search results for a user. It must be a JWT or a JSON token.

      • UserId (string) –

        The identifier of the user you want to filter search results based on their access to documents.

      • Groups (list) –

        The list of groups you want to filter search results based on the groups’ access to documents.

        • (string) –

      • DataSourceGroups (list) –

        The list of data source groups you want to filter search results based on groups’ access to documents in that data source.

        • (dict) –

          Data source information for user context filtering.

          • GroupId (string) – [REQUIRED]

            The identifier of the group you want to add to your list of groups. This is for filtering search results based on the groups’ access to documents.

          • DataSourceId (string) – [REQUIRED]

            The identifier of the data source group you want to add to your list of data source groups. This is for filtering search results based on the groups’ access to documents in that data source.

Return type:

dict

Returns:

Response Syntax

{
    'QuerySuggestionsId': 'string',
    'Suggestions': [
        {
            'Id': 'string',
            'Value': {
                'Text': {
                    'Text': 'string',
                    'Highlights': [
                        {
                            'BeginOffset': 123,
                            'EndOffset': 123
                        },
                    ]
                }
            },
            'SourceDocuments': [
                {
                    'DocumentId': 'string',
                    'SuggestionAttributes': [
                        'string',
                    ],
                    'AdditionalAttributes': [
                        {
                            'Key': 'string',
                            'Value': {
                                'StringValue': 'string',
                                'StringListValue': [
                                    'string',
                                ],
                                'LongValue': 123,
                                'DateValue': datetime(2015, 1, 1)
                            }
                        },
                    ]
                },
            ]
        },
    ]
}

Response Structure

  • (dict) –

    • QuerySuggestionsId (string) –

      The identifier for a list of query suggestions for an index.

    • Suggestions (list) –

      A list of query suggestions for an index.

      • (dict) –

        A single query suggestion.

        • Id (string) –

          The UUID (universally unique identifier) of a single query suggestion.

        • Value (dict) –

          The value for the UUID (universally unique identifier) of a single query suggestion.

          The value is the text string of a suggestion.

          • Text (dict) –

            The SuggestionTextWithHighlights structure that contains the query suggestion text and highlights.

            • Text (string) –

              The query suggestion text to display to the user.

            • Highlights (list) –

              The beginning and end of the query suggestion text that should be highlighted.

              • (dict) –

                The text highlights for a single query suggestion.

                • BeginOffset (integer) –

                  The zero-based location in the response string where the highlight starts.

                • EndOffset (integer) –

                  The zero-based location in the response string where the highlight ends.

        • SourceDocuments (list) –

          The list of document IDs and their fields/attributes that are used for a single query suggestion, if document fields set to use for query suggestions.

          • (dict) –

            The document ID and its fields/attributes that are used for a query suggestion, if document fields set to use for query suggestions.

            • DocumentId (string) –

              The identifier of the document used for a query suggestion.

            • SuggestionAttributes (list) –

              The document fields/attributes used for a query suggestion.

              • (string) –

            • AdditionalAttributes (list) –

              The additional fields/attributes to include in the response. You can use additional fields to provide extra information in the response. Additional fields are not used to based suggestions on.

              • (dict) –

                A document attribute or metadata field. To create custom document attributes, see Custom attributes.

                • Key (string) –

                  The identifier for the attribute.

                • Value (dict) –

                  The value of the attribute.

                  • StringValue (string) –

                    A string, such as “department”.

                  • StringListValue (list) –

                    A list of strings. The default maximum length or number of strings is 10.

                    • (string) –

                  • LongValue (integer) –

                    A long integer value.

                  • DateValue (datetime) –

                    A date expressed as an ISO 8601 string.

                    It is important for the time zone to be included in the ISO 8601 date-time format. For example, 2012-03-25T12:30:10+01:00 is the ISO 8601 date-time format for March 25th 2012 at 12:30PM (plus 10 seconds) in Central European Time.

Exceptions

  • kendra.Client.exceptions.ValidationException

  • kendra.Client.exceptions.ResourceNotFoundException

  • kendra.Client.exceptions.ThrottlingException

  • kendra.Client.exceptions.AccessDeniedException

  • kendra.Client.exceptions.ServiceQuotaExceededException

  • kendra.Client.exceptions.ConflictException

  • kendra.Client.exceptions.InternalServerException