Query
Searches an active index. Use this API to search your documents using query. The
Query
API enables to do faceted search and to filter results based on
document attributes.
It also enables you to provide user context that Amazon Kendra uses to enforce document access control in the search results.
Amazon Kendra searches your index for text content and question and answer (FAQ) content. By default the response contains three types of results.
-
Relevant passages
-
Matching FAQs
-
Relevant documents
You can specify that the query return only one type of result using the
QueryResultTypeFilter
parameter.
Each query returns the 100 most relevant results.
Request Syntax
{
"AttributeFilter": {
"AndAllFilters": [
"AttributeFilter"
],
"ContainsAll": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"ContainsAny": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"EqualsTo": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"GreaterThan": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"GreaterThanOrEquals": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"LessThan": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"LessThanOrEquals": {
"Key": "string
",
"Value": {
"DateValue": number
,
"LongValue": number
,
"StringListValue": [ "string
" ],
"StringValue": "string
"
}
},
"NotFilter": "AttributeFilter",
"OrAllFilters": [
"AttributeFilter"
]
},
"DocumentRelevanceOverrideConfigurations": [
{
"Name": "string
",
"Relevance": {
"Duration": "string
",
"Freshness": boolean
,
"Importance": number
,
"RankOrder": "string
",
"ValueImportanceMap": {
"string
" : number
}
}
}
],
"Facets": [
{
"DocumentAttributeKey": "string
",
"Facets": [
"Facet"
],
"MaxResults": number
}
],
"IndexId": "string
",
"PageNumber": number
,
"PageSize": number
,
"QueryResultTypeFilter": "string
",
"QueryText": "string
",
"RequestedDocumentAttributes": [ "string
" ],
"SortingConfiguration": {
"DocumentAttributeKey": "string
",
"SortOrder": "string
"
},
"SpellCorrectionConfiguration": {
"IncludeQuerySpellCheckSuggestions": boolean
},
"UserContext": {
"DataSourceGroups": [
{
"DataSourceId": "string
",
"GroupId": "string
"
}
],
"Groups": [ "string
" ],
"Token": "string
",
"UserId": "string
"
},
"VisitorId": "string
"
}
Request Parameters
For information about the parameters that are common to all actions, see Common Parameters.
The request accepts the following data in JSON format.
- AttributeFilter
-
Enables filtered searches based on document attributes. You can only provide one attribute filter; however, the
AndAllFilters
,NotFilter
, andOrAllFilters
parameters contain a list of other filters.The
AttributeFilter
parameter enables you to create a set of filtering rules that a document must satisfy to be included in the query results.Type: AttributeFilter object
Required: No
- DocumentRelevanceOverrideConfigurations
-
Overrides relevance tuning configurations of fields or attributes set at the index level.
If you use this API to override the relevance tuning configured at the index level, but there is no relevance tuning configured at the index level, then Amazon Kendra does not apply any relevance tuning.
If there is relevance tuning configured at the index level, but you do not use this API to override any relevance tuning in the index, then Amazon Kendra uses the relevance tuning that is configured at the index level.
If there is relevance tuning configured for fields at the index level, but you use this API to override only some of these fields, then for the fields you did not override, the importance is set to 1.
Type: Array of DocumentRelevanceConfiguration objects
Array Members: Minimum number of 0 items. Maximum number of 500 items.
Required: No
- Facets
-
An array of documents attributes. Amazon Kendra returns a count for each attribute key specified. This helps your users narrow their search.
Type: Array of Facet objects
Required: No
- IndexId
-
The identifier of the index to search. The identifier is returned in the response from the
CreateIndex
API.Type: String
Length Constraints: Fixed length of 36.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9-]*
Required: Yes
- PageNumber
-
Query results are returned in pages the size of the
PageSize
parameter. By default, Amazon Kendra returns the first page of results. Use this parameter to get result pages after the first one.Type: Integer
Required: No
- PageSize
-
Sets the number of results that are returned in each page of results. The default page size is 10. The maximum number of results returned is 100. If you ask for more than 100 results, only 100 are returned.
Type: Integer
Required: No
- QueryResultTypeFilter
-
Sets the type of query. Only results for the specified query type are returned.
Type: String
Valid Values:
DOCUMENT | QUESTION_ANSWER | ANSWER
Required: No
- QueryText
-
The input query text for the search. Amazon Kendra truncates queries at 30 token words, which excludes punctuation and stop words. Truncation still applies if you use Boolean or more advanced, complex queries.
Type: String
Length Constraints: Minimum length of 1. Maximum length of 1000.
Required: No
- RequestedDocumentAttributes
-
An array of document attributes to include in the response. You can limit the response to include certain document attributes. By default all document attributes are included in the response.
Type: Array of strings
Array Members: Minimum number of 1 item. Maximum number of 100 items.
Length Constraints: Minimum length of 1. Maximum length of 200.
Pattern:
[a-zA-Z0-9_][a-zA-Z0-9_-]*
Required: No
- SortingConfiguration
-
Provides information that determines how the results of the query are sorted. You can set the field that Amazon Kendra should sort the results on, and specify whether the results should be sorted in ascending or descending order. In the case of ties in sorting the results, the results are sorted by relevance.
If you don't provide sorting configuration, the results are sorted by the relevance that Amazon Kendra determines for the result.
Type: SortingConfiguration object
Required: No
- SpellCorrectionConfiguration
-
Enables suggested spell corrections for queries.
Type: SpellCorrectionConfiguration object
Required: No
- UserContext
-
The user context token or user and group information.
Type: UserContext object
Required: No
- VisitorId
-
Provides an identifier for a specific user. The
VisitorId
should be a unique identifier, such as a GUID. Don't use personally identifiable information, such as the user's email address, as theVisitorId
.Type: String
Length Constraints: Minimum length of 1. Maximum length of 256.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9_-]*
Required: No
Response Syntax
{
"FacetResults": [
{
"DocumentAttributeKey": "string",
"DocumentAttributeValueCountPairs": [
{
"Count": number,
"DocumentAttributeValue": {
"DateValue": number,
"LongValue": number,
"StringListValue": [ "string" ],
"StringValue": "string"
},
"FacetResults": [
"FacetResult"
]
}
],
"DocumentAttributeValueType": "string"
}
],
"QueryId": "string",
"ResultItems": [
{
"AdditionalAttributes": [
{
"Key": "string",
"Value": {
"TextWithHighlightsValue": {
"Highlights": [
{
"BeginOffset": number,
"EndOffset": number,
"TopAnswer": boolean,
"Type": "string"
}
],
"Text": "string"
}
},
"ValueType": "string"
}
],
"DocumentAttributes": [
{
"Key": "string",
"Value": {
"DateValue": number,
"LongValue": number,
"StringListValue": [ "string" ],
"StringValue": "string"
}
}
],
"DocumentExcerpt": {
"Highlights": [
{
"BeginOffset": number,
"EndOffset": number,
"TopAnswer": boolean,
"Type": "string"
}
],
"Text": "string"
},
"DocumentId": "string",
"DocumentTitle": {
"Highlights": [
{
"BeginOffset": number,
"EndOffset": number,
"TopAnswer": boolean,
"Type": "string"
}
],
"Text": "string"
},
"DocumentURI": "string",
"FeedbackToken": "string",
"Format": "string",
"Id": "string",
"ScoreAttributes": {
"ScoreConfidence": "string"
},
"TableExcerpt": {
"Rows": [
{
"Cells": [
{
"Header": boolean,
"Highlighted": boolean,
"TopAnswer": boolean,
"Value": "string"
}
]
}
],
"TotalNumberOfRows": number
},
"Type": "string"
}
],
"SpellCorrectedQueries": [
{
"Corrections": [
{
"BeginOffset": number,
"CorrectedTerm": "string",
"EndOffset": number,
"Term": "string"
}
],
"SuggestedQueryText": "string"
}
],
"TotalNumberOfResults": number,
"Warnings": [
{
"Code": "string",
"Message": "string"
}
]
}
Response Elements
If the action is successful, the service sends back an HTTP 200 response.
The following data is returned in JSON format by the service.
- FacetResults
-
Contains the facet results. A
FacetResult
contains the counts for each attribute key that was specified in theFacets
input parameter.Type: Array of FacetResult objects
- QueryId
-
The identifier for the search. You use
QueryId
to identify the search when using the feedback API.Type: String
Length Constraints: Minimum length of 1. Maximum length of 36.
Pattern:
[a-zA-Z0-9][a-zA-Z0-9-]*
- ResultItems
-
The results of the search.
Type: Array of QueryResultItem objects
- SpellCorrectedQueries
-
A list of information related to suggested spell corrections for a query.
Type: Array of SpellCorrectedQuery objects
- TotalNumberOfResults
-
The total number of items found by the search; however, you can only retrieve up to 100 items. For example, if the search found 192 items, you can only retrieve the first 100 of the items.
Type: Integer
- Warnings
-
A list of warning codes and their messages on problems with your query.
Amazon Kendra currently only supports one type of warning, which is a warning on invalid syntax used in the query. For examples of invalid query syntax, see Searching with advanced query syntax.
Type: Array of Warning objects
Array Members: Fixed number of 1 item.
Errors
For information about the errors that are common to all actions, see Common Errors.
- AccessDeniedException
-
You don't have sufficient access to perform this action. Please ensure you have the required permission policies and user accounts and try again.
HTTP Status Code: 400
- ConflictException
-
A conflict occurred with the request. Please fix any inconsistences with your resources and try again.
HTTP Status Code: 400
- InternalServerException
-
An issue occurred with the internal server used for your Amazon Kendra service. Please wait a few minutes and try again, or contact Support
for help. HTTP Status Code: 500
- ResourceNotFoundException
-
The resource you want to use doesn’t exist. Please check you have provided the correct resource and try again.
HTTP Status Code: 400
- ServiceQuotaExceededException
-
You have exceeded the set limits for your Amazon Kendra service. Please see Quotas for more information, or contact Support
to inquire about an increase of limits. HTTP Status Code: 400
- ThrottlingException
-
The request was denied due to request throttling. Please reduce the number of requests and try again.
HTTP Status Code: 400
- ValidationException
-
The input fails to satisfy the constraints set by the Amazon Kendra service. Please provide the correct input and try again.
HTTP Status Code: 400
See Also
For more information about using this API in one of the language-specific AWS SDKs, see the following: