如何在 Riak 中查询嵌套键? [英] How to query nested keys in Riak?

查看:69
本文介绍了如何在 Riak 中查询嵌套键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设您已经向 Riak 添加了一个存储桶,如下所示(使用 riak-php-client):

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();

    }
}';

如果您想访问Twitter"值.通过 Riak 访问该密钥的正确方法是什么?

If you want to access the "Twitter" value. What is the correct way to access that key via Riak?

推荐答案

如果您希望通过密钥以外的其他方式检索您的对象,则需要使用新的 二级索引 Riak 1.x 的特性

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

您可以通过将以下标头添加到 HTTP PUT 以存储对象来添加表示对象中Twitter"字段的二级索引:

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

(注意这需要使用 eleveldb 后端并在 Riak 配置中打开二级索引)

(note this requires the use of the eleveldb backend and turning on secondary indexes in the Riak config)

如果您想更直接地向我们提问,请随时在我们的 riak-users 邮件列表 - http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

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

编辑添加:此功能可通过 RiakObject->addIndex() 和 setIndex() 方法 并通过 RiakBucket->indexSearch() 方法.当前生成的文档似乎不是最新的;我很抱歉,我会看到它得到更新.

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.

这篇关于如何在 Riak 中查询嵌套键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆