We are adding full text searching functionality to our application.This tutorial assumes that you already completed part 1.Please refer to here for part 1.
Unfortunately,Couchbase does not have full text search feature as of version 2.2.0. So,it is advised to integrate Couchbase with elasticsearch to provide this.
Elastic search is a search analysis tool and a key value store which is getting more and more popular.
Here are the steps:
- Install Elasticsearch version 0.90.5 since this is the one compatible with Couchbase 2.2.0.Installation available here.
- Install Couchbase Elasticsearch plugin version(assuming you have Couchbase 2.2.0 installed) 1.2.0 following instructions here.Be careful with the version numbers since it does not work but with compatible version.Below is the version compatibility matrix:
- Verify that you can see administration console of elasticsearch upon starting on http://localhost:9200/_plugin/head/ .
- Install the Couchbase template using curl -XPUT http://localhost:9200/_template/couchbase -d @plugins/transport-couchbase/couchbase_template.json
- Create an index guardian on elasticsearch admin console http://localhost:9200/_plugin/head/
- Configure Couchbase to replicate data to elasticsearch:
- Navigate to the Couchbase Server admin interface.
- Select the Replications tab.
- Press the button labeled “Create Cluster Reference”
- Choose a name for your ElasticSearch cluster
- In the IP/Hostname and field provide an address and port of one of the nodes in your ES cluster (127.0.0.1:9091)
- Enter the Username and Password corresponding to your “couchbase.username” and “couchbase.password” settings in ElasticSearch. Refer to bullet no 2 for this.
- Press the “Save” button
- Press the button labeled “Create Replication”
- Select “guardian” bucket from source cluster
- Next select the cluster you defined in previous step
- Click advanced settings and set XDCR Protocol to version 1.
- Press the button labeled “Replicate”
- Verify on elasticsearch admin console that replication took place.
- Now that you completed the installation and configuration,it is time to run the code and try it out. Go to github and download the code available at https://github.com/selmantayyar/guardian-news-content/tree/version2 . This is the same github repository as the part one but on a different branch.To avoid installing couchnode again,just override your current local code copy with this.If this is the first time you are running this code,follow the instructions on readme file.Otherwise just type node app.js and enjoy it.
- But how does the searching work?Application does a REST call to elastic search server sending the keyword.A very simple post request,which makes elastic search really easy to use.By the way,a very nice introduction to elasticsearch is here.
$scope.searchNews = function () { console.log('scope keyword: '+$scope.form.keyword); var queryStr={ 'query': { 'query_string': { 'query': $scope.form.keyword, 'fields': ["trailText"] } } }; $http.post('http://localhost:9200/guardian/_search', queryStr). success(function(data) { console.log(data); searchResultService.setSearchresult(data); $location.url('/readNews'); }); };
Results & Analysis
To sum up, noticing that Couchbase(as of version 2.2.0) does not have any full text search feature is a bit disappointing.You need to install elasticsearch,replicate the data to it and handle all the data transfer issues,indexing issues(updating data sometimes could require indexes and mappings to be updated ..etc) and other potential issues.This is an additional operational burden. Couchbase is really good for storing data and retrieving it by key or by some other indexes.It is also easier to manage replicas.However, i still would expect full text search functionality here.