0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

IndexもGSIのパーティションキーも指定しているのにQuery condition missed key schema elementと言われるとき

Posted at

FilterExpressionに入れるべき内容がKeyConditionExpressionに入っていませんか?

こういう場合

const res = await docClient.query({
    TableName: "SampleTable",
    IndexName: "Value-Key-index",
    KeyConditionExpression: "#v = :v and #f = :f",
    ExpressionAttributeNames: {
        "#v": "Value",
        "#f": "f1",
    },
    ExpressionAttributeValues: {
        ":v": "hogehoge",
        ":f": "v1",
    },
}).promise();
{
  "errorType": "ValidationException",
  "errorMessage": "Query condition missed key schema element: Key",
  "trace": [
    // ...
  ]
}

GSIのパーティションキーは入ってる, Indexも指定しているパターンで起こります. 思っているエラー文と全然違うので解決がうまいこといきにくいですね.

FilterExpressionに入れ直してあげましょう.

const res = await docClient.query({
    TableName: "SampleTable",
    IndexName: "Value-Key-index",
    KeyConditionExpression: "#v = :v",
    FilterExpression: "#f = :f", // <= ここ
    ExpressionAttributeNames: {
        "#v": "Value",
        "#f": "f1",
    },
    ExpressionAttributeValues: {
        ":v": "hogehoge",
        ":f": "v1",
    },
}).promise();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?