Making and index field sortable

Back in your Index facet definition, unmark Sortable from all the fields.

Run a query, you will notice that the only option for sorting is Relevance.

Back on the Facets definition screen, mark _created_at as sortable:

Run your query again:

Now you can use the _category as the sorting parameter for your query. Behind the scenes a new query is executed and _category is the SortingConfiguration parameter of the Query operation.

For example, use this code to run a query and sort the results by the _created_at attribute in ascending order:

response=kendra.query(
        QueryText = query,
        IndexId = index_id,
        SortingConfiguration=
     {
         'DocumentAttributeKey': '_created_at',
         'SortOrder': 'ASC'
     }
 )
pp = pprint.PrettyPrinter(indent=1)
pp.pprint(response)

Hint: Make sure the attribute is sortable before running the query or you could obtain an error.