Search code examples
amazon-dynamodbdynamodb-queries

What's the best way to do an all-column query in dynamodb?


there, we got a dynamodb table with a bunch of columns, like stack-id, email, firstname, lastname, etc, whereas stack-id is the hash key and email is a GSI. Pretty standard stuff.

Now we are adding in a free-form search feature for our site, where user can just search anything in the search bar, say, 'foobar', and then we would search that string across all records for all columns, and if any match is found in any column, it's considered a match. This is easy for mysql and likes, but not for dynamodb.

So I came up with two potential ways to do this: first one is sorta brute force, where we make every column a GSI, then make multiple queries, each of which is for a specific column, then we aggregate the results of all the queries. Apparently, this is not a good idea.

Second way is adding a new column by concatenating all the columns of a record together. That column then contains every thing in all the other columns. We then make this column a GSI, and simply just query this column. Is this a good method?

I wonder if there are better ways to achieve this? thanks ahead.


Solution

  • This is not a good use case for DynamoDB. A better alternative would be to push the data to something else that is better designed for the type of searching you want to do, like ElasticSearch. Indexing Amazon DynamoDB Content with Amazon Elasticsearch Service Using AWS Lambda is a good reference for that.