Search code examples
javaamazon-dynamodbdynamodb-queries

Sorting dynamoDB query results using secondary local index


I have a table with the following fields in dynamoDB:

  1. primary key: reference_number
  2. sort key: user_id
  3. local secondary index on: isEligible
  4. local secondary index on: score

I want to fetch all documents corresponding to a reference_number with isEligible as true. I am doing this using a query, with a range condition on isEligible field. I now want the results of this query to be returned in order sorted by score field. Is there a way I can achieve this? All of this is being done in java


Solution

  • As currently modeled, no.

    If had a LSI with a composite sort key, ex:
    "true#85"
    "true#100"
    "false#45"

    You could then use a begins_with in your Query().