Case insensitive query in DB dynamo

I want to scan / query the dynamo DB table. DB Dynamo is case sensitive. I want to use Hash / Range keys sometimes as strings. Is there any way to resolve case insensitivity at the DB level of a dynamo? Or are there any other solutions? I ask Dynamo with the JAVA SDK

+11
java amazon-dynamodb
source share
2 answers

There are two possible ways that I can think.

1) Decide at the end of the application by setting up the circuit

For example, say you now have a β€œName” as a hash key when new users are added, adding them after creating their name in lower case

John --> john Doe --> doe 

Do not forget to save both the value ( name as a hash for the search) and ( displayName for displaying the target)

Now, before querying the database, you can convert the search to lowercase.

2) Using ElasticSearch: DyanmoDB table can be integrated with ElasticSearch, which can perform various search operations in your table ( link to link )

+10
source share

As mentioned in other answers, ElasticSearch seems to be a good option. However, when I came across a similar situation, I decided it that way.

I created a new attribute just for search. I saved the values ​​for the lowercase search in this attribute and searched by completing the query using the "CONTAINS" operator.

eg. If I have an item as follows:

 id: 1 username: 'fsmith' first_name: 'Franco' last_name: 'Smith' 

Now for the search, when I save the item, I save it with the newly created attribute 'search_term' as follows:

 id:1 username: 'fsmith' first_name: 'Franco' last_name: 'Smith' search_term: 'franco_smith_fsmith' 

Now, if I need to find a user named Franco Smith, I just make a request and use FilterExpression as (code in boto3 and python):

 FilterExpression = Attr('search_term').contains('franco') and Attr('search_term').contains('smith') 

However, this solution may not be very effective depending on your use case or scenario, since it uses requests, and you will be charged in accordance with the read items in accordance with the condition of the sort key.

0
source share

All Articles