不支持查询键条件:已经有一个哈希和一个范围键

Suh*_*pta 1 amazon-web-services node.js amazon-dynamodb

我正在尝试查询 Dynamomodified_time > 1 dayjstatus = Error

这里,JobStatusIndexGlobal Secondary Index拥有,modified_time作为Partition Keyjstatus作为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))
Run Code Online (Sandbox Code Playgroud)

但我收到一条错误消息:

ValidationException: Query key condition not supported
Run Code Online (Sandbox Code Playgroud)

这可能是什么原因?我只是不明白这个。

我经历了一些 SO 问题,但它没有解决问题。我已经准备好了所需的钥匙。我错过了什么?

F_S*_*O_K 5

您只能在分区键 (modified_time) 上使用等于运算符。要进行查询,您必须指定一个分区键。

根据您要实现的目标,您有很多不同的选择。很可能是您的分区键和排序键以错误的方式用于 GSI。如果将 jstatus 设为分区键,将 modified_time 设为排序键,则可以进行查询。

或者,您可以考虑执行scan,这不需要您指定任何索引或键。