Elixir:ExAws:DynamoDB:查询过滤器

时间:2019-05-14 20:46:20

标签: amazon-web-services amazon-dynamodb elixir

我正在使用图书馆https://github.com/ex-aws/ex_aws_dynamo

我在遇到query-filterquery一起工作的例子时遇到了问题,希望有人在这里分享他们可以分享的例子。

这里是我尝试过的内容,但返回错误。

[
  key_condition_expression: "highlight_request_id = :highlight_request_id",
  expression_attribute_values: [
    highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8"
  ],
  query_filter: %{
    range_id: %{
      attribute_value_list: ["9990-ORGANIZATION-Pampers"],
      comparison_operator: "EQ"
    }
  }
]

和我得到的错误。

{:error,
 {"ValidationException",
  "1 validation error detected: Value null at 'queryFilter.range_id.member.comparisonOperator' failed to satisfy constraint: Member must not be null"}}

不确定什么被认为是空的。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

确保您的查询是这样写的(改编自ex_aws_dynamo测试):

ExAws.Dynamo.query("person", [
  index_name: "email",
  key_condition_expression: "#email = :email",
  expression_attribute_names: %{"#email" => "email"},
  expression_attribute_values: [email: "person@test.com", last_name: "Person"],
  filter_expression: "last_name = :last_name"
]) |> ExAws.request()

我能够针对本地表成功运行此操作,您必须为模型填写适当的值。特别是,您需要包括index_name,并使用filter_expression,而不是query_filter

就您而言,我相信您会想要类似的东西

ExAws.Dynamo.query("person", [
  index_name: "highlight_request_id", # assuming that's the name of the index
  key_condition_expression: "#highlight_request_id = :highlight_request_id",
  expression_attribute_names: %{"#highlight_request_id" => "highlight_request_id"},
  expression_attribute_values: [highlight_request_id: "c692e65e-618f-45a3-ac12-d8103e6444c8", range_id: "9990-ORGANIZATION-Pampers"],
  filter_expression: "range_id = :range_id"
]) |> ExAws.request()

让我知道是否能使您更接近-再次使用最新版本的ex_aws_dynamo(目前为2.2.2)为我工作。