Saturday, August 22, 2015

How to recreate index for a bucket in Riak

As we all know that all of the data in the Riak is indexed using solr. And if we have to add another field into the index then we have to re-index the entire data again. I had to do this task last week so here I am sharing the steps that I followed.


1. Disassociate the index from the bucket. 

If you are using custom bucket type then use below:

Format:
curl -v -XPUT http://localhost:8098/types/acme/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":"_dont_index_"}}'

Example:
curl -v -XPUT http://localhost:8098/types/acme/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":"_dont_index_"}}'

If you are using default bucket type then use below:


Format:
curl -v -XPUT http://localhost:8098/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":"_dont_index_"}}'

Example:
curl -v -XPUT http://localhost:8098/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":"_dont_index_"}}'

2. Delete the index

Format:
curl -v -XDELETE http://localhost:8098/search/index/_index

Example:
curl -XDELETE http://localhost:8098/search/index/Users_index

3. Create the new schema which has the new field to be indexed.

Format:
curl -XPUT http://localhost:8098/search/schema/ \
     -H 'Content-Type:application/xml' \
     --data-binary @

Example:
curl -XPUT http://localhost:8098/search/schema/users-schema \
     -H 'Content-Type:application/xml' \
     --data-binary @solr-schema.xml

4. Re-create the index using new schema

Format:
curl -XPUT http://localhost:8098/search/index/_index \
     -H 'Content-Type: application/json' \
     -d '{"schema":""}'

Example:
curl -XPUT http://localhost:8098/search/index/Users_index \
     -H 'Content-Type: application/json' \
     -d '{"schema":"users-schema"}'

5. Associate the new index to the bucket.

If you are using custom bucket type then use below:

Format:
curl -v -XPUT http://localhost:8098/types/acme/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":""}}'

Example:
curl -v -XPUT http://localhost:8098/buckets/Users/props \
-H 'Content-Type: application/json' \
-d '{"props":{"search_index":"Users_index"}}'

6. Re-write all of the data in the bucket

For this I wrote some python code using the Riak python module.
Sudo code is as follows:
Get all keys from the bucket
FOREACH key
  Get the document for the key
  Save it back

This will re-index the data using the new schema.

Thursday, February 26, 2015

No form parameters are passed when submitting a form

The problem once identified was so stupid and obvious that for while I felt bad. I should have found it very quickly. Anyway, so what was happening is, I created a login for my new web application and after integrating with Spring security I was not able to login. I changed the log level of Spring security package to TRACE and then found that username and password are passed as empty strings.
Then I checked the request sent from browser and noticed that browser is not sending the params with the request.
Below is my html code of the login form:



I spent some time to figure out what is happening but it was already past midnight so I left it like that and slept.
In morning I looked into the code again and very quickly noticed that the input elements in the html does not have "name" attribute. Ooops !!! Very stupid mistake done by someone who has created many web applications.

But it shows that sometimes simple mistakes like this are hard to find.

~Manish