- Newest
- Most votes
- Most comments
Working on a different project today, I believe I have finally been able to solve the issue myself (which per default still exists).
By now, the error message has gotten slightly more verbose: from ""failed to create query: Rewrite first" to "failed to create query: Field 'path.keyword' not found. Rewrite first" - where "path" is the name of the field I tried to filter. This change can be correlated to an older MR in the OSS-library, where developers figured some error-messages weren't quite helpful. Arguably, the MR did indeed increase the response's usefulness.
Recreating the problem:
- creating a Bedrock Knowledge Base using a self-generated AWS OpenSearch Serverless-collection and -index as default-collection-generation won't create metadata-fields (or does it? I believe there is no such option yet)
- trying to query this KB using any filter on any text-field fails with above error message
Cause: can be deduced from this thread https://forum.opensearch.org/t/document-fields-do-not-always-get-keyword-entries/16474 .
--> Basically: the text-fields are lacking "keyword"-subfields for indexing
Solution / Workaround: create your index in the AOSS-collection using json-mode and make sure all text-fields which you want to filter on contain the necessary "keyword"-subfield. See below example for a fully functional json to create an index with 3 text-fields.
Example:
- make sure to include a non-filterable field for the bedrock-metadata !
- make sure to use the correct vector index settings (these ones are apt for using Titan Embeddings Text V2 and FAISS)
- in this example, the text-fields which shouild contain metadatae are "name" and "path" - and "description" is going to be my text-field for inputs (also filterable though)
{
"settings": {
"index.knn": "true",
"number_of_shards": 1,
"knn.algo_param.ef_search": 512,
"number_of_replicas": 0
},
"mappings": {
"properties": {
"embeddings": {
"type": "knn_vector",
"dimension": 1024,
"method": {
"name": "hnsw",
"engine": "faiss",
"space_type": "l2"
}
},
"description": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"bedrock-metadata": {
"type": "text",
"index": "false"
},
"name": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"path": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
answered 2 years ago
I did face this error message when I explicitly defined the filter field under the OpenSearch serverless index when configuring the metadata mapping fields. To fix the problem, I recreated the index and allowed Bedrock Knowledge base to add the filter mapping field automatically when tagging the metadata.json for the documents ingested into the Knowledgebase. Now I am able to apply the filters and it works all good.
answered 2 years ago
thanks for your reply back then, @nihilson. How did you allow BR KB to add filter mapping fields automatically? I havn't been able to do that yet. I did find another solution by now though (see accepted answer)...

Hi, I may not be able to give you the exact answer you are looking for, but recently we did a hackathon based on this workshop. The participants extended the solution with their own knowledge base and metadata - it worked very well for all the participants. I would suggest you compare your code/steps with this, hopefully you may be able to find a work-around. I would suggest to raise the main issue with AWS support, though. Thanks!
Hi, did you ever resolve this?
@Adam Weinberger: No, I did not. I eventually resorted to numerical replacements for these columns.
I am also seeing the same issues through the console and boto3. Filtering on strings does not work and always throws the same error mentioned above. Seems like this is a problem on the AWS side. AWS needs to fix this