0

How to search for records in JSON?

For example:

http://server.cc/riak/Scores/user12

{ v: "{"score":0,"tab":14,"gold":255}" }

How do I get all the records where the "gold" is more than 150 or equal 255?

I'm installed the Riak Search hook on bucket. I have used example from riak php lib.

 $client = new Riak(self::HOST, self::PORT);
 $bucket = $client->bucket("Scores");
 $results = $client->search("Scores", "gold:255")->run();

doesn't have results.

Can this be done through mapreduce?

2 Answers2

1

Just saw this pass by on the Riak Users mailing list:

http://lists.basho.com/pipermail/riak-users_lists.basho.com/2013-June/012286.html

"gold" is nested so I believe the search term would be :

v_gold:255

An underscore is used as the delimiter between nested keys.

-Alexander Sicular

Community
  • 1
  • 1
Joe
  • 25,000
  • 3
  • 22
  • 44
0

let, you have a json object like this:

var goldJson=
    [
        {"score": ,   "tab": , "gold": 255},
        {"score": ,   "tab": , "gold": 256},
        {"score": , "tab": , "gold": 257}
    ]

now you can get the gold more than 150 or equal to 255 by using the following codes:

for(var i = 0; i < goldJson.length; i++)
{
  if(goldJson[i].gold >150 || goldJson[i].gold == 255)
  {
    //get gold More than 150 or equal to 255
  }
}
Rayhan.iit.du
  • 279
  • 1
  • 4