Secondary Index ??

Russell Brown russelldb at basho.com
Wed Oct 5 09:12:04 EDT 2011


On 5 Oct 2011, at 13:45, Roland Karlsson wrote:

> Hi,
> 
> I might not look hard enough - but I cannot find how to use
> the secondary indices from the riakc erlang client interface.
> No example and no manual.

Ooops, we'll get on that.

> 
> I need a simple example how to write an indexed object
> and also a simple example how to look it up via the index.
> 
> This is my own try to write and lookup an object
> It does not work :)

Doesn't work crash or doesn't work, you get {ok, []} when you query the index?

> 
> ----------------------------------------------------------
> write_index(Pid) ->                                                                                                                                                                                                                             
>    Bucket = <<"persons">>,
>    Key = <<"bosse">>,
>    Index = {<<"lives">>, <<"sumatra">>},

Indexes should have a suffix of either _bin for binary or _int for integer.

>    Obj = riakc_obj:new(Bucket, Key, <<"1949">>),
>    Meta = dict:store(?MD_INDEX, Index, dict:new()),

Index should be a list. If it *was* in a list you would have got an error {error,<<"{precommit_fail,[{unknown_field_type,<<\"lives\">>}]}">>} on put. 

>    Obj2 = riakc_obj:update_metadata(Obj, Meta),
>    riakc_pb_socket:put(Pid, Obj2).
> ----------------------------------------------------------
> read_index(Pid) ->
>    Bucket = <<"persons">>,
>    Index = <<"lives">>,

Again, the suffix. or you'll get {error,<<"{inputs,[{unknown_field_type,<<\"lives\">>}]}">>} when you do that get_index.

>    IndexKey = <<"sumatra">>,
>    riakc_pb_socket:get_index(Pid, Bucket, Index, IndexKey).                                                                                                                                                               
> ----------------------------------------------------------

Do _all_ that and I get {ok,[[<<"persons">>,<<"bosse">>]]} as the output from get_index.

We'll get those docs updated.

Cheers

Russell
> 
> 
> /Roland
> 
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com




More information about the riak-users mailing list