Question:
Thank you for taking the time in reading my question.
My scenario is this. I have a geopoints table in dynamodb.
It consists of:
object_type(String HASH)
id(String RANGE)
lat(Number GSI RANGE)
lng(Number GSI RANGE)
It has indexes of:
object_type-lat-index(object_type-hash lat-range)
object_type-lng-index(object_type-hash lng-range)
What I want to do:
IndexName: "object_type-lat-index",
KeyConditionExpression: "object_type=:otype AND (lat BETWEEN :llat AND :glat) AND (lng BETWEEN :llng AND :glng)",
I want to be able to query lat and lng by getting the betweens of a least lat and greater lat, and least lng and greater lng
I can’t seem to find it in the dynamodb docs. Can this be done or am I implementing it correctly? Because the error is returning something like ‘Can only have 1 or 2 conditions’
Answer:
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GSI.html#GSI.Querying
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html
The way it works is the query works against the table itself (the keys defined in the table) or a GSI. You cannot combine multiple GSIs and the table HK in the same query.
2 options here:
1) perform 2 queries against the 2 indexes and intersect the results on the client
2) do one 1 query against one of the indexes w/ a filter expression that works with the other expression (so basically, for example: query on lat with a filter for long).