- Newest
- Most votes
- Most comments
The issue you're experiencing with filtering string-based date metadata in Amazon Bedrock Knowledge Base using OpenSearch Serverless is a known problem. It appears to be related to how text fields are indexed in OpenSearch.
The error message "failed to create query: Field 'mydatestring.keyword' not found. Rewrite first" suggests that OpenSearch is trying to use a keyword subfield for filtering, which doesn't exist for your date string field.
This problem occurs because when Bedrock Knowledge Base creates the index in OpenSearch Serverless, it doesn't automatically create the necessary keyword subfields for text fields that are used for filtering.
To resolve this issue, you have a couple of options:
-
Create your own index in the OpenSearch Serverless collection before setting up the Bedrock Knowledge Base. When creating the index, make sure to include keyword subfields for all text fields you want to use for filtering. Here's an example of how you might define a field in your index mapping:
"mydatestring": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } -
Instead of using string fields for dates, consider using numeric fields to represent dates (e.g., as Unix timestamps). Numeric fields don't require keyword subfields and should work with filtering out of the box.
-
If possible, recreate your Knowledge Base and allow Bedrock to automatically add the filter mapping fields when ingesting your documents with metadata. Some users have reported success with this approach.
If you continue to face issues after trying these solutions, it may be worth reaching out to AWS support for further assistance, as this seems to be a recurring issue with Bedrock Knowledge Base and OpenSearch Serverless integration.
Sources
Bedrock knowledge base filtering using string fields returns exception - "failed to create query: Rewrite first" | AWS re:Post
Bedrock knowledge base filtering on string / text fields returns error - "failed to create query: Field 'name.keyword' not found Rewrite first" | AWS re:Post
answered a year ago
Relevant content
asked a year ago
