Riak Search on KV data in erlang terms

Ryan Zezeski rzezeski at basho.com
Wed Jan 23 00:20:43 EST 2013


The erlang extractors don't work when writing the data via HTTP as they
store the data as a binary.  I.e. [{"name", "bob"}] becomes <<"[{\"name\",
\"bob\"}]">> instead of the proplist you expect.  This is because the
extractor assumes the object data is already properly decoded.  It is
possible to write erlang terms via the erlang client, but I wouldn't
recommend it as it is not the common case and I feel like there are other
issues lurking in Riak if you do this.  If there a particular reason you
are trying to store erlang terms?  Are you worried about space?  I would
just stick with JSON or XML if that is acceptable.


On Tue, Jan 22, 2013 at 10:15 AM, Takeshi Matsumura
<takeshi4126 at gmail.com>wrote:

> Hi,
> I tried to store erlang data and query them by using the Riak Search
> without success so far, and thus would like to ask if I'm doing the right
> thing. Riak Search was enabled in the app.config file and the server was
> restarted. The pre-commit hook was installed from the command line.
> bin/search-cmd install mybucket
> The erlang data that I uploaded is a proplists with a single pair of key
> and value.
> [{"name", "bob"}]
> It was uploaded by using the curl command with Content-Type
> "application/x-erlang". (hoge.erl.txt contains the above erlang terms).
> curl -v -d @hoge.erl.txt -X PUT -H "content-type: application/x-erlang" "
> http://localhost:8098/riak/mybucket/bob"
> I could get the document by issuing curl command to
> "/riak/mybucket/bob". The HTTP response header contained the correct
> Content-Type, "application/x-erlang".
> Then I run the Riak Search from the command line.
> bin/search-cmd search mybucket "name:bob"
> Unfortunately, the result said "Found 0 results".
> As I wondered if this is a problem related to the erlang terms, I tried
> the same with a JSON data that is found in the "Indexing and Querying KV
> Data" page but setting "application/json" to the Content-type.
> {
>  "name":"Alyssa P. Hacker",
>  "bio":"I'm an engineer, making awesome things.",
>  "favorites":{
>               "book":"The Moon is a Harsh Mistress",
>               "album":"Magical Mystery Tour"
>              }
> }
> Then the Riak Search could find this document with the query
> "name:Alyssa*".
> According to the "Indexing and Querying KV Data" page of the Riak
> document, erlang terms can be queried by using the Riak Search. However, it
> is unclear to me if it is enabled by default because the page says XML,
> JSON, and plain-text encodings are supported out of the box but it doesn't
> mention the erlang terms.
> I followed the "Other Data Encodings" section and set the
> "riak_search_kv_erlang_extractor" module, but it didm't change the
> situation.
> curl -XPUT -H 'content-type: application/json' \
>     http://localhost:8098/riak/mybucket \
>     -d '{"props":{"search_extractor":{"mod":"riak_search_kv_erlang_extractor", "fun":"extract", "arg":"my_arg"}}}'
> I changed the data as follows and uploaded but it didn't help either.
> [{<<"name">>, <<"bob">>}]
> I appreciate any hints for me to go forward. Thank you in advance.
> Best regards,
>  Takeshi
> _______________________________________________
> riak-users mailing list
> riak-users at lists.basho.com
> http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20130123/9496cb46/attachment.html>

More information about the riak-users mailing list