1

I am trying to query Dynamo for modified_time > 1 day and jstatus = Error

Here, JobStatusIndex is the Global Secondary Index having, modified_time as the Partition Key and jstatus as the sort key.

 dynamo.query({
    TableName: "Jobs",
    IndexName: "JobStatusIndex", // Global Secondry Index
    KeyConditionExpression: `modified_time >= :ter and jstatus = :ste`,
    ExpressionAttributeValues: {
      ':ter': moment().subtract(1, 'day').unix(),
      ':ste': "Error"
    }
  },(err) => console.log(err))

But I get an error that says:

ValidationException: Query key condition not supported

What could be the reason for this? I just don't get this.

I have gone through some SO questions, but it didn't solve the problem. I already have the required keys in place. What am I missing?

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328
  • may be this help you [link here](https://stackoverflow.com/questions/31830888/dynamodb-query-error-query-key-condition-not-supported) – Manjeet Thakur Dec 12 '17 at 11:18

1 Answers1

5

You can only use an equals operator on your partition key (modified_time). And to do a query, you must specify a single partition key.

You have a lot of different options depending on what you are trying to achieve. Most likely is you have your partition key and sort key the wrong way around for your GSI. If you make jstatus your partition key and modified_time your sort key you can do the query.

Alternatively you could consider doing a scan, which does not require you to specify any index or keys.

F_SO_K
  • 13,640
  • 5
  • 54
  • 83