Alex,

Assuming you've already made your bucket-type with "map" as the
datatype, then "bucket.new()" will return you a Map instead of a
RiakObject. Translating your example above:

key = bucket.new('lionelmessi')
key.registers['name'].assign('Messi')
key.registers['team'].assign('Barcelona')
key.counters['number'].increment(10)
key.store()

Note that because Maps are based on mutation operations and not
replacing the value with new ones, you can later do this without
setting the entire value:

key.counters['number'].increment(1)
key.store()

This will also change your searches, however, in that the fields will
be suffixed with the embedded type you are using:

r = client.fulltext_search('ix_footballers', 'team_register:Barcelona')

Hope that helps!

On Tue, Aug 19, 2014 at 2:59 PM, Alex De la rosa
<alex.rosa....@gmail.com> wrote:
> Imagine I have a Riak object "footballer" with some static fields: name,
> team, number. I store them like this now:
>
> 1: CREATE INDEX FOR RIAK SEARCH
> curl -XPUT "http://148.251.140.229:8098/search/index/ix_footballers";
>
> 2: CREATE BUCKET TYPE
> riak-admin bucket-type create tp_footballers
> '{"props":{"allow_mult":false,"search_index":"ix_footballers"}}'
> riak-admin bucket-type activate tp_footballers
>
> 3: INSERT A PLAYER
> bucket = client.bucket_type('tp_footballers').bucket('footballers')
> key = bucket.new('lionelmessi', data={'name_s':'Messi',
> 'team_s':'Barcelona', 'number_i':10}, content_type='application/json')
> key.store()
>
> 4: SEARCH FOR BARCELONA PLAYERS
> r = client.fulltext_search('ix_footballers', 'team_s:Barcelona')
>
> So far so good :) BUT... what if I want to have a field "goals_i" that is a
> counter that will be incremented each match day with the number of goals he
> scored? What is the syntax/steps to do to set up "footballers" as a MAP and
> then put a COUNTER inside? I know is possible as I read it in some data dump
> some Basho employee passed me some time ago, but I can't manage to see how
> to do it now.
>
> Thanks!
> Alex
>
> _______________________________________________
> riak-users mailing list
> riak-users@lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>



-- 
Sean Cribbs <s...@basho.com>
Software Engineer
Basho Technologies, Inc.
http://basho.com/

_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to