Happy Valentines Day!
Wait, What is Riak?
If you think you know me, you had best learn what Riak is and how to use it if you want to continue being friends.
Ok, so what is new in Riak?
Lots of things! Riak 2.0 comes with better search capability, new built in distributed data types, options for stronger consistency, and improved configuration management for deployments in the cloud.
Of all the features, I am most excited about both Search 2.0 and the new
Conflict-free replicated data types
otherwise known as
CRDT. These are
and I may write about these later.
Great, so what is Riak JSON?
Riak JSON focuses on JSON documents. Why JSON? Because (lets be honest here) it is currently gaining in popularity and people want to use it. JSON is now popping up all the time for me, and I want better tooling to help my work be more efficient (while still being correct) while working with distributed databases.
Are you not like me and have a specific serialized format you actually care about? Riak JSON will show you how to build out such a specific interface on top of Riak, or you can use the lower level Solr / Yokozuna API directly which is underneath Riak JSON. This is also something we (at Basho) can help you with.
Ok, so to get started with Riak JSON we start off with the branch of Riak that has everything put together. If need a pre-built package please yell at me (nicely) on twitter and I may accomodate you. Riak JSON will work on any Riak 2.0 install.
Note, the content below is the same material within the the slides prepared for the talk.
Building from source:
Enable both search and riak json within the
Fire up Riak
The Java client has the following dependencies to deal with the HTTP, serialization to JSON, and logging concerns:
- Apache HTTP Client
Using the Java / Scala library:
Define a document class:
Define a schema:
Add some data, riak will generate the keys for you if you wish, or you may assign your own.
Query by key:
Search! Find One Thing:
Find ALL the things!
"$page":1 to control the pagination
Lastly, you can query Riak using a few different approaches:
Riak Search 2.0 (Solr / Yokozuna) Style:
And finally cleanup:
A key interest of mine is making Riak more developer friendly, and while there will continue to be gaps as we iterate, I feel that the 2.0 is a step in the right direction to achieve this.