Thursday, August 23, 2012

Riak HTTP API Cheat Sheet

Riak HTTP API Cheat Sheet

Listing Buckets and Keys

To list all buckets,
 http://localhost:8098/buckets?buckets=true  

To list all keys within a particular bucket,
 http://localhost:8098/buckets/bucket-name/keys?keys=true  

To list a single object based on key,
 http://localhost:8098/buckets/bucket-name/keys/key-value  

Secondary Index

To find an object based on secondary index,
 http://localhost:8098/buckets/bucket-name/index/index-name_bin/index-value  

Link Walking 

To walk a link from a source key,
 curl -v http://localhost:8098/riak/bucket-name/key-value/_,link-name,1/_,link-name,1  

The walk result provides the interesting results, including secondary index and links on the return objects.
 --AZBlFqksfFqU1it69r5Ygf99o0p  
 X-Riak-Vclock: a85hYGBgzGDKBVIcypz/fvrf7r6bwZTInMfKMOXIypN8WQA=  
 Location: /riak/schema_schema2/campaigns-efg  
 Content-Type: application/json; charset=UTF-8  
 Link: </riak/schema_schema2/folder%3Acampaigns-folder1>; riaktag="PARENT", </riak/schema_schema2>; rel="up"  
 Etag: 4qk1erJBcxtRZxJBDFgxK3  
 Last-Modified: Wed, 22 Aug 2012 21:01:08 GMT  
 x-riak-index-uri_bin: _schemas_schema2_campaigns_campaigns-efg  
 {"bucket":"schema_schema2","contextType":"CAMPAIGN","json":{"name":"campaigns-efg","id":"campaigns-efg"},"name":"campaigns-efg","relationshipMap":{"PARENT":["folder:campaigns-folder1"]},"schema":"schema2","type":"CAMPAIGN","uri":"/schemas/schema2/campaigns/campaigns-efg","uriIndex":"_schemas_schema2_campaigns_campaigns-efg","version":"1.0"}  

The highlighted entries show the Riak Link and secondary index on the current object. This is a valuable debugging tool to ensure the object has the correct relationship.

Search

Use search command line tool to execute free text search,
 search-cmd search bucket-name query  
Query string is something like "type:Folder", etc.

To use the HTTP API,
 curl http://localhost.com:8098/solr/bucket-name/select?q=name:foo  

No comments:

Post a Comment