How to query nested keys in Riak?

故事扮演 提交于 2019-12-22 00:24:48

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!