On Mon, Jun 25, 2012 at 6:06 AM, Venki Yedidha
<venkatesh.yedi...@gmail.com> wrote:
>                   I have a document in which my Riak object is linked with
> tag name 'city' to nearly 1000 other objects.
>                   However, If I use /bucketname/keyname/_,city,1
>                        It lists me all cities linked with my object.
>                        Instead of returning the entire json, I need data
> regarding 'chicago'  city.

Hi, Venkatesh. Are you asking about getting the list of links instead
of the list of objects that those links point to?  If so, what you
want to do is just get /bucketname/keyname - the links for that object
are returned in a Link header just like the one you sent with your
last write.  For example:

    $ curl -X PUT -H "content-type: text/plain" -H "link:
</riak/venki/b>; riaktag=\"first\", </riak/venki/c>;
riaktag=\"second\"" http://localhost:8098/riak/venki/a --data "AAAAAA"

    $ curl -i http://localhost:8098/riak/venki/a
    ...snip...
    Link: </riak/venki/b>; riaktag="first", </riak/venki/c>;
riaktag="second", </riak/venki>; rel="up"
    ...snip...

    AAAAAA

You'll need to parse and filter that header yourself.

The way to get Riak to do the filter for you is to use the "link"
phase type in a MapReduce query.[1] For example, getting just the link
tagged "first" from my example object would look like this:

    $ curl -X POST -H "content-type: application/json"
http://localhost:8098/mapred --data
"{\"inputs\":[[\"venki\",\"a\"]],\"query\":[{\"link\":{\"tag\":\"first\"}}]}"

    HTTP/1.1 200 OK
    Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
    Date: Tue, 26 Jun 2012 13:47:14 GMT
    Content-Type: application/json
    Content-Length: 23

    [["venki","b","first"]]

That return value is a JSON list of links, where each link has the
form [Bucket, Key, Tag].  For example, if I asked for all links in the
"venki" bucket:

    $ curl -X POST -H "content-type: application/json"
http://localhost:8098/mapred --data
"{\"inputs\":[[\"venki\",\"a\"]],\"query\":[{\"link\":{\"bucket\":\"venki\"}}]}"

    HTTP/1.1 200 OK
    Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue)
    Date: Tue, 26 Jun 2012 13:48:55 GMT
    Content-Type: application/json
    Content-Length: 46

    [["venki","b","first"],["venki","c","second"]]

I have both links in a JSON array.

HTH,
Bryan

[1] http://wiki.basho.com/MapReduce.html#Link

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

Reply via email to