OK - I saw that in the code. But - why do the identity function return a list containing a bucket, key pair? Why not a tuple? If it returns a tuple, then the output of e.g. get_index() could be used as an input to a new mapreduce. Would that not be nice?
Or am I missing something? /Roland ----- Original Message ----- From: "Russell Brown" <[email protected]> To: "Roland Karlsson" <[email protected]> Cc: [email protected] Sent: Thursday, October 6, 2011 11:38:51 AM Subject: Re: Secondary Index ?? And this time, to the list as well :$ On 6 Oct 2011, at 10:22, Roland Karlsson wrote: > Maybe my question below was not clear enough. > > I wonder why get_index() returns a list > of lists (containing bucket/key pairs), when mapred() > wants a list of tuples (containing bucket/key pairs). > Looks like an unnecessary conversion by the user too me. When you call get_index from the riak-erlang-client you are in fact running an m/r operation. The input is an index query. The riak-erlang-client specifies a reduce phase of riak_kv_mapreduce:reduce_identity/2, so you get back the output from that (a list of [b,k] lists). The Java client takes a different approach and has a reduce function that just returns the keys, in a list. This is to provide parity with the output of the HTTP API (which returns the JSON {"keys": ["k1", "k2"]}) If you wish, you can run an m/r job with an index input and subsequent map/reduce phases to ensure the output is the shape you want it to be. get_index() is just a convenience function for one such m/r job. Cheers Russell > > /Roland > > > > > ----- Original Message ----- > From: "Roland Karlsson" <[email protected]> > To: [email protected] > Sent: Wednesday, October 5, 2011 4:33:17 PM > Subject: Re: Secondary Index ?? > > 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 > > _______________________________________________ > 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
