Search is not working in RIAK

Joe Caswell jcaswell at basho.com
Fri Jan 24 13:33:22 EST 2014


Ajit,

  Riak Search doesn't exactly support nested fields.  The default extractor
will flatten the fields in the input by joining the field and subfield names
with underscore.  (example below)

I'm not totally clear on what you are trying to accomplish, so I'll run
through an example and hope it clears up some confusion.

The data as pasted in the original email confuses the extractor since the
same fields are duplicated with the object:
```
root at sitea2:~# search-cmd install testbucket

 :: Installing Riak Search <--> KV hook on bucket 'testbucket'.

root at sitea2:~# curl http://sitea2:8098/buckets/testbucket/keys/emp1 -XPUT -H
"content-type: application/json" -d '
 {
  "employee":{
              "employee_name":"Raghav Maitra",
              "employee_id":"1001",
              "designation":"Technical Analyst",
              "emp_contract_no":"1987-XXVI",
              "department":
                     {"dept_name":"ADW",
                      "sub_dept_name":"A1",
                      "dept_id":"A1-2001",
                      "dept_description":"Analysis and Devlopement Wing",
                      "dept_site_name":"Diego Gracia"
                     }
              "employee_name":"Ajit",
              "employee_id":"1002",
              "designation":"Technical Analyst",
              "emp_contract_no":"2001-XXVI",
              "department":
                     {"dept_name":"ADW",
                      "sub_dept_name":"A1",
                      "dept_id":"A1-2001",
                      "dept_description":"Analysis and Devlopement Wing",
                      "dept_site_name":"Diego Gracia"
             }
 }'
<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,215}]},
         {riak_kv_wm_object,handle_common_error,3,
             [{file,"src/riak_kv_wm_object.erl"},{line,1046}]},
         {webmachine_resource,resource_call,3,
             [{file,"src/webmachine_resource.erl"},{line,186}]},
         {webmachine_resource,do,3,
             [{file,"src/webmachine_resource.erl"},{line,142}]},
         {webmachine_decision_core,resource_call,1,
             [{file,"src/webmachine_decision_core.erl"},{line,48}]},
         {webmachine_decision_core,accept_helper,1,
             [{file,"src/webmachine_decision_core.erl"},{line,612}]},
         {webmachine_decision_core,decision,1,
             
[{file,"src/webmachine_decision_core.erl"},{line,580}]}]}}</pre><P><HR><ADDR
ESS>mochiweb+webmachine web server</ADDRESS></body></html>
```


Adding them separately allows each to be indexed:


```
root at sitea2:~# curl http://sitea2:8098/buckets/testbucket/keys/emp1 -XPUT -H
"content-type: application/json" -d '{
"employee":{
             "employee_name":"Raghav Maitra",
             "employee_id":"1001",
             "designation":"Technical Analyst",
             "emp_contract_no":"1987-XXVI",
             "department":
                    {"dept_name":"ADW",
                     "sub_dept_name":"A1",
                     "dept_id":"A1-2001",
                     "dept_description":"Analysis and Devlopement Wing",
                     "dept_site_name":"Diego Gracia"
                    },
            }
}'

root at sitea2:~# curl http://sitea2:8098/buckets/testbucket/keys/emp2 -XPUT -H
"content-type: application/json" -d '{
"employee":{
             "employee_name":"Ajit",
             "employee_id":"1002",
             "designation":"Technical Analyst",
             "emp_contract_no":"1987-XXVI",
             "department":
                    {"dept_name":"ADW",
                     "sub_dept_name":"A1",
                     "dept_id":"A1-2001",
                     "dept_description":"Analysis and Devlopement Wing",
                     "dept_site_name":"Diego Gracia"
                    },
            }
}'
```


After these puts, the following terms exist in the search index:


```
 {{<<"testbucket">>,{<<"employee_department_dept_description">>,<<"Analysis"
>>}}
 {{<<"testbucket">>,{<<"employee_department_dept_description">>,<<"and">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_description">>,<<"Devlopeme
nt">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_description">>,<<"Wing">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_id">>,<<"A1-2001">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_name">>,<<"ADW">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_site_name">>,<<"Diego">>}}
 {{<<"testbucket">>,{<<"employee_department_dept_site_name">>,<<"Gracia">>}}
 {{<<"testbucket">>,{<<"employee_department_sub_dept_name">>,<<"A1">>}}
 {{<<"testbucket">>,{<<"employee_designation">>,<<"Analyst">>}}
 {{<<"testbucket">>,{<<"employee_designation">>,<<"Technical">>}}
 {{<<"testbucket">>,{<<"employee_emp_contract_no">>,<<"1987-XXVI">>}}
 {{<<"testbucket">>,{<<"employee_employee_id">>,<<"1001">>}}
 {{<<"testbucket">>,{<<"employee_employee_id">>,<<"1002">>}}
 {{<<"testbucket">>,{<<"employee_employee_name">>,<<"Ajit">>}}
 {{<<"testbucket">>,{<<"employee_employee_name">>,<<"Maitra">>}}
 {{<<"testbucket">>,{<<"employee_employee_name">>,<<"Raghav">>}}
```

And search-cmd can query as expected:

```
root at sitea2:~# search-cmd search testbucket
employee_department_dept_id:A1-2001

 :: Searching for 'employee_department_dept_id:A1-2001' / '' in
testbucket...

------------------------------

index/id: testbucket/emp1
p -> [0]
score -> 0.35355339059327373

------------------------------

index/id: testbucket/emp2
p -> [0]
score -> 0.35355339059327373

------------------------------

 :: Found 2 results.

root at sitea2:/tmp# search-cmd search testbucket
"employee_employee_name:Raghav"

 :: Searching for 'employee_employee_name:Raghav' / '' in testbucket...

------------------------------

index/id: testbucket/emp1
p -> [0]
score -> 0.35355339059327373

------------------------------

 :: Found 1 results.

root at sitea2:/tmp# search-cmd search testbucket employee_employee_name:Ajit

 :: Searching for 'employee_employee_name:Ajit' / '' in testbucket...

------------------------------

index/id: testbucket/emp2
p -> [0]
score -> 0.35355339059327373

------------------------------

```

Joe Caswell

From:  "Ajit Prasad(RMG00)" <ajit.aprasad at igate.com>
Date:  Thursday, January 23, 2014 12:19 AM
To:  "riak-users at lists.basho.com" <riak-users at lists.basho.com>
Subject:  Search is not working in RIAK

Hi,
Search doesn¹t seem to work on a normal JSON file. Have created index on
JSON file and installed the search on the bucket also.
$search-cmd search out2_buk "employee_name:\"Ajit\""
:: Searching for 'employee_name:"Ajit"' / '' in out2_buk...
------------------------------
:: Found 0 results.
 
File content is pasted below :
"employee":{
             "employee_name":"Raghav Maitra",
             "employee_id":"1001",
             "designation":"Technical Analyst",
             "emp_contract_no":"1987-XXVI",
             "department":
                    {"dept_name":"ADW",
                     "sub_dept_name":"A1",
                     "dept_id":"A1-2001",
                     "dept_description":"Analysis and Devlopement Wing",
                     "dept_site_name":"Diego Gracia"
                    }
             "employee_name":"Ajit",
             "employee_id":"1002",
             "designation":"Technical Analyst",
             "emp_contract_no":"2001-XXVI",
             "department":
                    {"dept_name":"ADW",
                     "sub_dept_name":"A1",
                     "dept_id":"A1-2001",
                     "dept_description":"Analysis and Devlopement Wing",
                     "dept_site_name":"Diego Gracia"
 
            }
 
 
 
 
Thanks and regards,
Ajit
Cell:+91-9980084384
 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Disclaimer~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Information contained and transmitted by this e-mail is confidential and
proprietary to iGATE and its affiliates and is intended for use only by the
recipient. If you are not the intended recipient, you are hereby notified
that any dissemination, distribution, copying or use of this e-mail is
strictly prohibited and you are requested to delete this e-mail immediately
and notify the originator or mailadmin at igate.com. iGATE does not enter into
any agreement with any party by e-mail. Any views expressed by an individual
do not necessarily reflect the view of iGATE. iGATE is not responsible for
the consequences of any actions taken on the basis of information provided,
through this email. The contents of an attachment to this e-mail may contain
software viruses, which could damage your own computer system. While iGATE
has taken every reasonable precaution to minimise this risk, we cannot
accept liability for any damage which you sustain as a result of software
viruses. You should carry out your own virus checks before opening an
attachment. To know more about iGATE please visit www.igate.com
<http://www.igate.com> .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_______________________________________________ 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/20140124/e805f5a1/attachment.html>


More information about the riak-users mailing list