0

I have a DynamoDB table like depicted in the attached image and I'm looking for ways to query the table based on lon and lat fields. More specifically, I'm looking for all the results with Lon between X and Y and Lat between A and B.

Is there any way to do that ? I created indexes for both Lon and Lat but the values are strings.

Thanks a lot for your help !!

DynamoDB table

Benoit Morel
  • 23
  • 1
  • 10

1 Answers1

0

you can come up with a good hash function(lets say f) and have the below schema for dynamodb

| pk          | sk               |  lat  | lon  | name 
| hashvalue1  | 48.80#2.35#Fac   | 48.80 | 2.35 | Fac du
| hashvalue1  | 48.83#2.36#Groupe| 48.83 | 2.36 | Groupe Hos

here f(48.80, 2.35) = hashvalue1
f(48.83, 2.36) = hashvalue1

And whenever you have to query for lat1 and lon1, calculate f(lat1, lon1) and query the db. But the problem with this solution is coming up with a good hashing function because in the worst case you may have to recalculate hash of every entered value in db otherwise it may become a hot key. this approach is well documented here and here.

I would suggest go with elastic search, it will give you much more flexibility. in terms of future use cases.

best wishes
  • 5,789
  • 1
  • 34
  • 59