Sunday 15 March 2015

DynamoDB Scan with multiple, nested JSON keys (PHP) -



DynamoDB Scan with multiple, nested JSON keys (PHP) -

my info stored in single table "events" in dynamodb in next schema "_id" hash key , "microtime" range key (example info below):

{ "_id": { "s": "ae3761b5-b73b-4fb9-ae5a-5cc230b8fa11" }, "data": { "m": { "name": { "s": "jeff" }, "purchase_value": { "n": "25" }, "user_id": { "n": "1201" } } }, "microtime": { "n": "14147568808639" } }

i using aws php sdk 2.7.0 scan database based on filters (in example, primary hash key "_id"). code below works (returns right entry):

$client = dynamodbclient::factory(array( 'key' => 'key', 'secret' => 'secret', 'region' => 'eu-west-1' )); $iterator = $client->getiterator('scan', array( 'tablename' => 'events', 'scanfilter' => array( '_id' => array( 'attributevaluelist' => array( array('s' => "ae3761b5-b73b-4fb9-ae5a-5cc230b8fa11") ), 'comparisonoperator' => 'eq' ), ) )); foreach ($iterator $item) { print_r($item); }

now when seek scan based on info within of "data" element, i can't matching entries. illustration code below (i trying extract data.name=jeff):

$iterator = $client->getiterator('scan', array( 'tablename' => 'events', 'scanfilter' => array( 'data.name' => array( 'attributevaluelist' => array( array('s' => "jeff") ), 'comparisonoperator' => 'eq' ), ) )); foreach ($iterator $item) { print_r($item); }

anyone can see issues code, or in fact not possible extract info comparing values within of json document? in advance suggestions!

edit

i've tried next code dynamodb php sdk documentation (http://docs.aws.amazon.com/aws-sdk-php/v3/api/aws/dynamodb/dynamodb-2012-08-10.html#scan) - still no success. can retrieve when scanning using primary hash/range key, , other ("first-level") key, not using key within of document (map/list) in example. see below:

$iterator = $client->getiterator('scan', array( 'tablename' => 'events', 'scanfilter' => array( 'data' => array( 'attributevaluelist' => array( array( 'm' => array( 'name' => array("s"=>"jeff"), ), ), ), 'comparisonoperator' => 'eq', ), ), ));

solution issue:

$iterator = $client->getiterator('scan', array( 'tablename' => 'event_test2', 'filterexpression' => 'event.customer_name = :filter', "expressionattributevalues" => array(":filter"=>array("s"=>"jeff")), ));

more info here: https://forums.aws.amazon.com/thread.jspa?threadid=164470

php json amazon-web-services amazon-dynamodb

No comments:

Post a Comment