Thanx - now it works!

Your explanations were very good.

I also found I had to change from bitcask to eleveldb.

I added one object with the same index and then I got the answer

{ok, [[<<"persons">>,<<"kenny">>],[<<"persons">>,<<"bosse">>]]}

Hmmm ... why is it a list in a list?

/Roland




----- Original Message -----
From: "Russell Brown" <[email protected]>
To: "Roland Karlsson" <[email protected]>
Cc: [email protected]
Sent: Wednesday, October 5, 2011 3:12:04 PM
Subject: Re: Secondary Index ??


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
> [email protected]
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com


_______________________________________________
riak-users mailing list
[email protected]
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to