2013-04-04 52 views
2

考虑一个JSON对象,如:您可以在Riak的重复字段上创建二级索引吗?

{ 
    name: 'ben', 
    employer: 'The Sherwin-Williams Company', 
    emails: ['[email protected]', '[email protected]'] 
} 

在MongoDB中,你可以索引电子邮件领域,这样你可以找到“[email protected]”任何对象作为电子邮件。这在Riak中可能吗?从阅读the docs我看不出来。

+0

您打算使用哪种客户端库? – 2013-04-04 22:27:59

+0

做一些客户端库允许它而不是其他?如果是这样,那么我会选择一个允许它的人。 – 2013-04-04 23:12:57

回答

2

您当然可以,但您必须手动输入索引条目。

下面是Ruby的一个例子:

require 'riak' 

client = Riak::Client.new(:protocol => "pbc", :host => "127.0.0.1", :pb_port => 10047, :http_port => 10048) 

ben = client['people'].get_or_new('ben') 

ben.data = { :name => "ben", 
      :employer => "The Sherwin-Williams Company", 
      :emails => ['[email protected]', '[email protected]'] } 

ben.indexes['email_bin'] << "[email protected]" 
ben.indexes['email_bin'] << "[email protected]" 

ben.store 

现在你可以看看它通过Ruby库,或通过Web浏览器在http://127.0.0.1:10018/buckets/people/index/email_bin/[email protected]

在我的系统中,这将返回: {"keys":["ben"]}

我知道Java和Ruby Riak库支持添加/编辑索引条目,但我必须检查其他条目,然后回复给您。

相关问题