0

I am trying to get riak to return specific data instead of the keys.

I started with the fasttrack introduction. I can't find a way to retrieve the right data.

I am trying with this query (from here):

{"inputs":"goog",
 "query":[{"map":{"language":"javascript",
                  "source":"function(value, keyData, arg) { var data = Riak.mapValuesJson(value)[0]; if(data.High && parseFloat(data.High) > 600.00) return [value.key]; else return [];}",
                  "keep":true}}]
}

I am trying to retrieve series of objects like {"Date":"YYYY-MM-DD","Open":123,"Close":123,"Volume":12345}.

How can achieve this?

Coyote
  • 2,454
  • 26
  • 47

1 Answers1

1

In the function you passed in to the map phase you return either the key ([value.key]) or nothing ([]) in the case the criteria are not fulfilled. This is why you are only seeing the keys.

If you instead change [value.key] to [data] you should see the actual data of the record being returned.

If the function instead were to return [value], the full identifier of the record (bucket and key) would be returned, and it would be possible to chain other map phase functions after this one. This would allow further processing and might make it easier to reuse the filtering. If you at the end of processing still wanted to get the data of the records returned, there is an existing function that will do just that. The specification for is as follows:

{"map":{"language":"erlang","module":"riak_kv_mapreduce","function":"map_object_value"}}

Christian Dahlqvist
  • 1,665
  • 12
  • 9
  • Hi, This is a good step forward. But what happens if I want only a few fields I tried returning `[{"Date":data.Date, "Open":data.Open, "Close":data.Close, "Volume":data.Volume}]` But this fails with an error. How can I format this data? I manage to return the data itself: `[[data.Date, data.Open, data.Close, data.Volume]]` but without the keys I need to return – Coyote Oct 04 '12 at 15:38
  • Create a string containing the data you need and return that, e.g. in JSON format. – Christian Dahlqvist Oct 04 '12 at 16:39