问题
Say you have added a bucket to Riak like below (Using riak-php-client):
$myData = '{
"24":{
"1": {
"Ryan":{
"email":"chris@test.com",
"title":"Boss",
"Phone":"555.555.5555",
"Fax":"555.555.5555",
"Twitter":"@testingtwitter"
}
}
}
}';
$data = json_decode($myData, true);
$object->setData($myData);
$object->store();
}
}';
If you want to access the "Twitter" value. What is the correct way to access that key via Riak?
回答1:
If you wish to retrieve your object by something other than the key, you would need to use the new secondary indexes feature of Riak 1.x
You could add a secondary index that represents the "Twitter" field in your object by adding the following header to an HTTP PUT
to store an object:
x-riak-index-twitter_bin: @testingtwitter
This would allow you to retrieve it via:
curl http://localhost:8098/buckets/mybucket/index/twitter_bin/@testingtwitter
(note this requires the use of the eleveldb backend and turning on secondary indexes in the Riak config)
If you wish to ask us questions a little more directly, please feel free to do so on our riak-users mailing list - http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
Edit to add: This functionality is available in the Riak PHP client via the RiakObject->addIndex() and setIndex() methods and getting via the RiakBucket->indexSearch() method. It appears that current generated documentation isn't up to date; my apologies, I'll see that it gets updated.
来源:https://stackoverflow.com/questions/9708368/how-to-query-nested-keys-in-riak