Riak Search pre-commit hook

Mark Phillips mark at basho.com
Tue Aug 14 14:22:12 EDT 2012


Thanks for the extensive write up, Mark.

I'll take a look at our docs and see if there's a way to make sure
this process is easier in the future for those who are less determined
and diligent than you. :) Any and all suggestions (and pull requests
[1]) are of course encouraged.

Mark
twitter.com/pharkmillups

[1] https://github.com/basho/riak_wiki

On Wed, Aug 8, 2012 at 5:02 PM, Mark Volkmann <r.mark.volkmann at gmail.com> wrote:
> On Wed, Aug 8, 2012 at 1:56 PM, Mark Volkmann <r.mark.volkmann at gmail.com>
> wrote:
>>
>> I'm trying to learn how to configure Riak Search to automatically index
>> documents added to a given bucket. I have four nodes in my cluster. Here is
>> what I tried:
>>
>> * modified etc/app.config for each node to set {enabled, true} in the
>> riak_search section
>> * stopped and restarted the cluster
>> * cd'ed to the bin directory of the first node in the cluster and entered
>> "./search-cmd install users"
>> * entered "curl http://localhost:8091/riak/users" to verify that the
>> pre-commit hook was added
>> I see this in the middle of the output:
>> "precommit": [
>>       {
>>         "mod": "riak_search_kv_hook",
>>         "fun": "precommit"
>>       }
>>     ],
>> * added a document to the users bucket with this command:
>> curl -XPUT http://localhost:8091/buckets/users/keys/1234 -H 'Content-type:
>> application/json' -d '{name: "Joe", address: {street: "123 Some Street",
>> zip: 12345}}'
>>
>> The output is below. Notice the "hook_crashed" part.
>>
>> <html><head><title>500 Internal Server
>> Error</title></head><body><h1>Internal Server Error</h1>The server
>> encountered an error while processing this request:<br><pre>{error,
>>     {error,badarg,
>>         [{erlang,iolist_to_binary,
>>              [{hook_crashed,
>>                   {riak_search_kv_hook,precommit,error,function_clause}}],
>>              []},
>>
>> {wrq,append_to_response_body,2,[{file,"src/wrq.erl"},{line,204}]},
>>          {riak_kv_wm_object,handle_common_error,3,
>>              [{file,"src/riak_kv_wm_object.erl"},{line,974}]},
>>          {webmachine_resource,resource_call,3,
>>              [{file,"src/webmachine_resource.erl"},{line,169}]},
>>          {webmachine_resource,do,3,
>>              [{file,"src/webmachine_resource.erl"},{line,128}]},
>>          {webmachine_decision_core,resource_call,1,
>>              [{file,"src/webmachine_decision_core.erl"},{line,48}]},
>>          {webmachine_decision_core,accept_helper,0,
>>              [{file,"src/webmachine_decision_core.erl"},{line,583}]},
>>          {webmachine_decision_core,decision,1,
>>
>> [{file,"src/webmachine_decision_core.erl"},{line,554}]}]}}</pre><P><HR><ADDRESS>mochiweb+webmachine
>> web server</ADDRESS></body></html>
>>
>> What am I doing wrong?
>
>
> I have it working now. Here's what I had to do.
>
> 1) Define a schema file for my bucket.
> 2) Set it with "./search-cmd set-schema {bucket-name} {file-path}".
> 3) Learn that when referencing nested fields in JSON structures, all
> ancestor names must be included and separated with underscores. I didn't see
> that in any documentation, but learned it from the presentation video at
> http://nosql.mypopescu.com/post/5475701359/riak-search-explained.
> 4) When PUTing JSON, put double-quotes around keys. It's JSON, not
> JavaScript literal object syntax.
>
> Here's the schema I created. Note the field name "address_zip".
>
> %% Schema for 'users'
> {
>   schema,
>   [
>     {version, "1.1"},
>     {n_val, 3},
>     {default_field, "name"},
>     {analyzer_factory, {erlang, text_analyzers,
> whitespace_analyzer_factory}}
>   ],
>   [
>     %% Field named "zip" is are indexed as integer
>     {field, [
>       {name, "address_zip"},
>       {type, integer},
>       {analyzer_factory, {erlang, text_analyzers, integer_analyzer_factory}}
>     ]},
>
>     %% Everything else is a string
>     {dynamic_field, [
>       {name, "*"},
>       {type, string},
>       {analyzer_factory, {erlang, text_analyzers,
> whitespace_analyzer_factory}}
>     ]}
>   ]
> }.
>
> I hope this helps someone in the future!
>
> --
> R. Mark Volkmann
> Object Computing, Inc.
>
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
>




More information about the riak-users mailing list