DynamoDB:查询非关键属性的全局二级索引

时间:2014-01-13 06:08:01

标签: php database amazon-web-services nosql amazon-dynamodb

我想通过对global secondary index的非关键属性应用条件来查询GSI。我尝试了下面的代码,但它不起作用。

代码:

$result = $this->dbClient->query(array(
                        'TableName' => 'myTable',
                        'IndexName' => 'myIndex',
                        'AttributesToGet' => array('id'),
                        'KeyConditions' => array(
                            // Key attribute
                            'userId' => array(
                                    'ComparisonOperator' => ComparisonOperator::EQ,
                                    'AttributeValueList' => array(
                                        array(Type::NUMBER => $value)
                                    )
                                ),
                            // This is non-key attribute
                            'length' => array(
                                    'ComparisonOperator' => ComparisonOperator::LE,
                                    'AttributeValueList' => array(
                                        array(Type::NUMBER => $upperLimit),
                                    )
                                ),
                            ),
                        ));  

编辑: 我收到错误消息

Query key condition not supported

2 个答案:

答案 0 :(得分:0)

您只能查询关键属性。你需要在"长度"上创建一个GSI。 - GSI存在的原因是为了这个目的。

答案 1 :(得分:0)

来自http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html

  • 对于表格的查询,您只能在表格上有条件    首要的关键        属性。您必须将散列键属性名称和值指定为EQ        条件。您可以选择指定第二个条件,参考范围        关键属性。

  • 对于索引的查询,您只能对索引键属性有条件。 您必须将索引散列属性名称和值指定为EQ条件。您 可以选择指定第二个条件,指的是索引键范围 属性。

相关问题