As per my understanding. A query operation will seek results on the mentioned index until one of the following condition is met
So DynamoDB query will fetch results as per above criteria and then it will apply the FilterExpression so it is quite possible that it might not return any results to you, so it will return empty set and a LastEvaluatedKey
But I also read the following in the documentation
Unlike a Scan operation, a Query operation never returns both an empty result set and a LastEvaluatedKey value.
Can someone please help in explaining what does the above documentation statement actually mean?
Because in practice when I user queryPage API with limit and FilterExpression I am getting opposite of it, i.e. I am getting an empty set as well as LastEvaluatedKey.
Is my above understanding correct? It is possible to get both an empty results and lastEvaluatedKey value? Or I am missing something because of which I am getting empty results? (as per documentation I should not get it. It would be great if I don't get empty results)
I am also struggling with same problems as you, after reading the document, I find the following description explaining why. According to Amazon document, "In a Query operation, DynamoDB retrieves the items in sorted order, and then processes the items using KeyConditionExpression and any FilterExpression that might be present."
So it explained why you are getting those results. The filter operation is processed after the query results, so no mater you apply FilterExpression or not, the Query operations are no difference, that's why you see the lastEvaluatedKey is presented, and it's no difference with the one without apply FilterExpression.
So the only possible way to achive what you want is using Global Secondary Indexes, the column you want to filter, you can put it as sort key. In this case, you can query withRangeKeyCondition().
They have updated the documentation, and its inline with what your experience is. From the documentation link in the question : Note: A Query operation can return an empty result set and a LastEvaluatedKey if all the items read for the page of results are filtered out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With