Creating a view


I’m very new to Couchbase, and testing some queries on it these days.

In Couchbase, it seems that we should pre-define ‘view’ before I execute query. So, every sample article explains how to define views for each condition such as 'by_country", “by_lanuage”, and “by_age”.

I can create some of pre-defined views for our service. However, our service also has a kind of search ui to let our customers make a custom search condition themselves. For example, customers can make a condition like ‘country == US AND language == English AND age >= 20 AND score >= 10’. We have more than 10 felids which can be selected in the search ui.

I see that some of view examples use ‘emit multiple keys’ and use ‘start & end keys’ for multiple column search. However, It seems that we can’t use that way. The number of selected columns is not pre-defined and their values are not always sequential.

Therefore, I’m thinking to programatically create a view on every customer’s search request. Do you guys think it is a good approach in Couchbase? I actually worry of two things below:

  1. Creating a view may take a long time since it should create a index. So, the search request may take too long time.

  2. I’ve found how to programatically a view with API. However it seems that this api is only for development, not production. Is there any API to publish a production view?

What do you guys think of my issue?

Thank you guys in advance!

Sunku -

Given your use-case is textual search, you may want to consider Couchbase + ElasticSearch. There is a connector that makes integration a breeze:

As for the answers to your questions:

  1. Yes, indexing can take awhile (initially) and you may see some issues if you are creating views on the fly (see above)
  2. I am not 100% sure here, but I don’t believe you can publish a view from a client. You can publish views directly to production, but it’s not advised. See here:

Once again, given your use-case I think the ElasticSearch/Couchbase connector is your best bet.