BTW, I didn't see this actually covered in the wiki, but in my testing just now, I found that instead of "source" you can pass "name" and specify an existing JS function (of which Riak has several included to assist with map & reduce phases). (Sadly, the provided JS functions have no code comments, lol...)
Ex: root@dev:~# curl -i -d '{"inputs":"test","query":[{"map":{"language":"javascript","name":"Riak.mapValuesJson","keep":true}}]}' -H "Content-Type: application/json" http://127.0.0.1:8098/mapred HTTP/1.1 200 OK Server: MochiWeb/1.1 WebMachine/1.7.3 (participate in the frantic) Date: Thu, 07 Jul 2011 06:22:00 GMT Content-Type: application/json Content-Length: 53 [{"name":"John Smith","age":28,"company":"Facebook"}] * You can view the pre-built JS functions here: https://github.com/basho/riak_kv/blob/master/priv/mapred_builtins.js <http://www.loomlearning.com/> Jonathan Langevin Systems Administrator Loom Inc. Wilmington, NC: (910) 241-0433 - jlange...@loomlearning.com - www.loomlearning.com - Skype: intel352 * On Thu, Jul 7, 2011 at 2:15 AM, Jonathan Langevin < jlange...@loomlearning.com> wrote: > I've not attempted map/reduce before, so this was a learning experience for > me. > Pay attention to the brackets in the function :-) > > root@dev:~# curl -i -d > '{"inputs":"test","query":[{"map":{"language":"javascript","source":"function(val) > { return [val]; }","keep":true}}]}' -H "Content-Type: application/json" > http://127.0.0.1:8098/mapred > HTTP/1.1 200 OK > Server: MochiWeb/1.1 WebMachine/1.7.3 (participate in the frantic) > Date: Thu, 07 Jul 2011 06:13:59 GMT > Content-Type: application/json > Content-Length: 690 > > [{"bucket":"test","key":"riak_developer_1","vclock":"a85hYGCQz2DKBVJszUkMW8O6MpgSGfNYGTSKI4/zQSRYWB2KzmIKA9Wzebeeg0p0I6ln4FbowBQGmf9BVxQqoVqCpN7QaDmmMFA9s+V0CaiEYBlCPXvl6buYwkD1rF7SbFCJ3RVI5t9el4wpDFTPftr/F1TiHZJ6lu1OWzCFQe5/uAlmvmUlQj2TGB8DpjBQPcvrpSpQifoqhHq2+27cmMKg8DTtvQCVaKtGUs/WcgpTGKieyeHuF6jElhqk8Dnlch2LMKvTDwdMYZAxrxNSoBLLahHqGU+xOwGFmVCFQdHyf4oCVP1aVAnBPfswJVhYz562hBqEInzq1mVMYVA0mn68BDXGRCsKEY0v38dgEWZc4dsOFb5mG4UcWzd+70OWyAIA","values":[{"metadata":{"Links":[],"X-Riak-VTag":"7FfI4n3AtRNBPjLymMbvoJ","content-type":"text/json","X-Riak-Last-Modified":"Wed, > 01 Jun 2011 04:36:38 GMT","X-Riak-Meta":[]},"data":"{\"name\":\"John > Smith\",\"age\":28,\"company\":\"Facebook\"}"}]}] > * > > > <http://www.loomlearning.com/> > Jonathan Langevin > Systems Administrator > Loom Inc. > Wilmington, NC: (910) 241-0433 - jlange...@loomlearning.com - > www.loomlearning.com - Skype: intel352 > * > > > > On Wed, Jul 6, 2011 at 11:53 PM, Matt Graham <mdg...@gmail.com> wrote: > >> curl -i -d >> >> '{"inputs":"test","query":[{"map":{"language":"javascript","source":"function(value) >> { return value; }","keep":true}}]}' -H "Content-Type: >> application/json" http://127.0.0.1:8098/mapred >> > >
_______________________________________________ riak-users mailing list riak-users@lists.basho.com http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com