1

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?

user782860
  • 2,689
  • 5
  • 18
  • 15
  • There is no key, there is a compound object as json. Are you even able to fetch the data? Or is your problem just how to access a PHP variable? – hakre Mar 14 '12 at 18:59
  • I can access the entire Riak object, but would like to query only for the "Twitter" value and not the entire object. – user782860 Mar 14 '12 at 19:09
  • Riak is a key value store. As long as you retrieve the value stored with the key (which is not *Twitter* here but the whole object), you will get the whole object on retrieval. If it's worth, you can run a map / reduce server-side to only retrieve something else, but I assume that's not worth the operation for your case. – hakre Mar 14 '12 at 19:19
  • @hakre Thanks for the clarification. The reason why I'd like only the "Twitter" value, is b/c the object I'm going to be working with in production is going to be much larger than the $myData object above. So it seems silly to query a large object when all I need is the "Twitter" value. Maybe this is the way to do things in Riak, it's just hard wrapping my mind around that. – user782860 Mar 14 '12 at 19:35
  • Riak is there for dead simple operations. It's not an object database that allows you access to properties of objects or such. Maybe couchdb has the functionality you're looking for, it is aware of documents, subkeys etc. – hakre Mar 14 '12 at 19:42
  • Riak should be fine for what I'm doing, even if it's not an object database like couchdb. It's more of a matter, being a newbie, understanding how to model the data. Any suggestions would be appreciated. Maybe use Riak search, restructuring the data, etc, etc.. – user782860 Mar 14 '12 at 19:51
  • 1
    We've added this ability in Riak 1.x with the eleveldb backend and secondary indexes - see my answer below. – Brian Roach Mar 20 '12 at 16:39

1 Answers1

3

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.

Brian Roach
  • 76,169
  • 12
  • 136
  • 161