From Riak docs:
Riak Search is enabled in the app.config file. Simply change the setting to “true” in Riak Search Config section (shown below).
%% Riak Search Config
{riak_search, [
%% To enable Search functionality set this 'true'.
{enabled, false}
]},
Restart riak node:
$ sudo riak restart
From Riak docs:
$ search-cmd install my_bucket_name
Because we just added a post-commit hook the data already in there won't be in the index (sadtrombone.wav)
Warning: Probably not wise to do this if you have millions of keys already ... :)
With simple Python script:
import riak
rc = riak.RiakClient(host="127.0.0.1", port=8087, prefix="riak", transport_class=riak.RiakPbcTransport)
keys = rc.bucket("my_bucket_name").get_keys()
for key in keys:
key1 = rc.bucket("my_bucket_name").get(key)
key1.store()
Using the command line (docs):
Example json data in my_bucket_name
:
{
"titlet":"Laptop bag",
"price":10.0
}
Test command:
$ search-cmd search my_bucket_name "title:Laptop"
Simple:
import riak
rc = riak.RiakClient(host="127.0.0.1", port=8087, prefix="riak", transport_class=riak.RiakPbcTransport)
search_query = rc.search("my_bucket_name", "title:Laptop")
for result in search_query.run():
key = result.get()
key_data = key.get_data()
print "Loaded key:", key.get_key()
print "Key data:\n", key_data
Just return the field we search on:
import riak
rc = riak.RiakClient(host="127.0.0.1", port=8087, prefix="riak", transport_class=riak.RiakPbcTransport)
field = "title"
keyword = "Laptop"
search_query = rc.search("my_bucket_name", field + ":" + keyword)
for result in search_query.run():
key = result.get()
key_data = key.get_data()
print "Loaded key:", key.get_key()
print field + ":", key_data[field]