查询条件缺少关键模式元素:dynamoDB Scala 中的 source_transaction_id

Query condition missed key schema element: source_transaction_id in dynamoDB Scala

我正在尝试使用二级索引执行查询,如下所示

val valMap = new ValueMap()
      .withString(":v_source_transaction_id", "843f45ad-cb1d-4f41-9ede-366c9304e447")
      //.withString(":source_transaction_trace_id","843f45ad-cb1d-4f41-9ede-366c9304e443")

println(valMap)
//search is defined then extract dates from search.. else continue with simple logic.
val keyConditionExpression =   """source_transaction_id =
                                 | :v_source_transaction_id""".stripMargin


val spec = new QuerySpec()
  .withProjectionExpression("source_transaction_id, transaction_date")
  .withKeyConditionExpression(keyConditionExpression)
  .withValueMap(valMap)
  .withMaxResultSize(2)


case class DataItems(transaction_date: String)
val itemList = new ListBuffer[DataItems]
val items = table.getIndex("gsi-settlement").query(spec)

println(table.getIndex("gsi-settlement"))

val iterator = items.iterator()
while (iterator.hasNext) {
  val next = iterator.next()
  itemList += DataItems(next.getString("transaction_date"))
}
itemList.foreach(println)

此处 gsi 结算是二级索引,源交易 ID 是主键,我收到以下错误:

[AmazonDynamoDBException: Query condition missed key schema element:  source_transaction_id

试试这个:

val keyConditionExpression = """source_transaction_id = :v_source_transaction_id""".stripMargin

当前您的 keyConditionExpression 显示为

source_transaction_id =
   :v_source_transaction_id

错误:AmazonDynamoDBException: Query condition missed key schema element: source_transaction_id 提示您在查询中缺少 GSI 密钥