Skip to content

Instantly share code, notes, and snippets.

@mks0ff
Forked from drewkerrigan/YOKOZUNA.md
Created July 12, 2019 21:01
Show Gist options
  • Save mks0ff/c6aa4668424203c737788696cc0c9ba4 to your computer and use it in GitHub Desktop.
Save mks0ff/c6aa4668424203c737788696cc0c9ba4 to your computer and use it in GitHub Desktop.
Yokozuna Setup

Create a schema based on the default one

https://github.com/basho/yokozuna/blob/develop/priv/default_schema.xml

Upload your schema

curl -XPUT -H 'Content-Type: application/xml'  http://localhost:8098/search/schema/drew_schema --data-binary @"my_schema.xml"

Create an index docs here

curl -i -XPUT http://localhost:8098/search/index/my_index   -H 'content-type: application/json'   -d '{"schema":"drew_schema"}'

Create a bucket type

./rel/riak/bin/riak-admin bucket-type create data '{"props":{"search_index":"my_index"}}'
./rel/riak/bin/riak-admin bucket-type activate data

Add data


curl -XPUT -H 'content-type: application/json' 'http://localhost:8098/types/data/buckets/people/keys/drew' \
  -d '{"drewname": "Drew", "drewlastname": "Kerrigan"}'
  
curl -XPUT -H 'content-type: application/json' 'http://localhost:8098/types/data/buckets/people/keys/drew' \
  -d '{"drewname": "Josh", "drewlastname": "Yambert"}'
  

Query for data

curl 'http://localhost:8098/search/my_index?q=drewname:Drew' -H 'Content-Type: application/json'

Result

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">17</int><lst name="params"><str name="shards">127.0.0.1:8093/solr/my_index</str><str name="q">drewname:Drew</str><str name="fq">(_yz_node:riak@127.0.0.1 AND (_yz_pn:64 OR (_yz_pn:61 AND (_yz_fpn:61)) OR _yz_pn:60 OR _yz_pn:57 OR _yz_pn:54 OR _yz_pn:51 OR _yz_pn:48 OR _yz_pn:45 OR _yz_pn:42 OR _yz_pn:39 OR _yz_pn:36 OR _yz_pn:33 OR _yz_pn:30 OR _yz_pn:27 OR _yz_pn:24 OR _yz_pn:21 OR _yz_pn:18 OR _yz_pn:15 OR _yz_pn:12 OR _yz_pn:9 OR _yz_pn:6 OR _yz_pn:3))</str></lst></lst><result name="response" numFound="1" start="0" maxScore="1.4054651"><doc><str name="drewlastname">Kerrigan</str><str name="drewname">Drew</str><str name="_yz_id">data_people_drew_15_4urLFrTSRGICDPrlXB2f5w</str><str name="_yz_rk">drew</str><str name="_yz_rt">data</str><str name="_yz_rb">people</str></doc></result>
</response>

Search for Josh

curl 'http://localhost:8098/search/my_index?q=drewname:Josh'

Result

<?xml version="1.0" encoding="UTF-8"?>
<response>
<lst name="responseHeader"><int name="status">0</int><int name="QTime">18</int><lst name="params"><str name="shards">127.0.0.1:8093/solr/my_index</str><str name="q">drewname:Josh</str><str name="fq">(_yz_node:riak@127.0.0.1 AND ((_yz_pn:62 AND (_yz_fpn:62)) OR _yz_pn:61 OR _yz_pn:58 OR _yz_pn:55 OR _yz_pn:52 OR _yz_pn:49 OR _yz_pn:46 OR _yz_pn:43 OR _yz_pn:40 OR _yz_pn:37 OR _yz_pn:34 OR _yz_pn:31 OR _yz_pn:28 OR _yz_pn:25 OR _yz_pn:22 OR _yz_pn:19 OR _yz_pn:16 OR _yz_pn:13 OR _yz_pn:10 OR _yz_pn:7 OR _yz_pn:4 OR _yz_pn:1))</str></lst></lst><result name="response" numFound="1" start="0" maxScore="1.4054651"><doc><str name="drewlastname">Yambert</str><str name="drewname">Josh</str><str name="_yz_id">data_people_drew_13_6OkBHRFWXnl55BBbiMOCW1</str><str name="_yz_rk">drew</str><str name="_yz_rt">data</str><str name="_yz_rb">people</str></doc></result>
</response>

Search in Ruby

client = Riak::Client.new pb_port: 8087
result = client.search("my_index", "drewlastname:Yambert")
client[result["docs"][0]["_yz_rb"]].get(result["docs"][0]["_yz_rk"], {type: result["docs"][0]["_yz_rt"]})

Notes

PB Proto File

https://github.com/basho/riak_pb/blob/develop/src/riak_kv.proto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment