I'm trying to query a DynamoDB table and check to see if the query I pass in is included in the partition key of the table index.
For example I have a DynamoDB table with example data below.
+-----+----------------+---------------------------------------------+
| id | title | description |
+-----+----------------+---------------------------------------------+
| id1 | My Title One | This is an awesome item in my database |
| id2 | My Title Two | This is also an awesome item in my database |
| id3 | The Item Three | Hello World |
+-----+----------------+---------------------------------------------+
I have a global index on the property title. The primary partition key is id.
What I want to do is take in a search query from the user and match all items for the title.
I have the following code that will match the user term exactly to the title.
const params = {
ExpressionAttributeValues: {
":q": {
S: req.query.q
}
},
KeyConditionExpression: "title = :q",
TableName: "MyTable",
IndexName: 'title-index'
};
dynamodb.query(params, (err, titles) => {
if (err) {
return res.status(500).send({"Error": "Error"});
}
titles = titles.Items
.map(item => AWS.DynamoDB.Converter.unmarshall(item));
return res.send(titles);
});
So if the user searches for My Title One it will return the result with the id of id1. Now I want to add support for if the user enters My Title, I want it to return id's id1 AND id2. Currently it returns nothing, since nothing exactly matches.
I know this is possible with using DynamoDB scans instead of queries, but due to the fact that my table has so many items, doing a scan in this case seems like it would be SO inefficient in terms of performance and cost.
What is the easiest way to achieve this?