Search:

Search all manuals
Search this manual
Manual
Couchbase Developer's Guide 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Server 2.0 Manual
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Finding Data with Views
Chapter Sections
Chapters

4.3. Building an Index

To retrieve the information you want, you query a view and receive a result set from Couchbase Server. There are two possible types of views which influence when Couchbase Server will actually build an index based on that view:

When you are almost done with design and testing of a view, you can query the development view and have Couchbase Server index based on the entire set of entries. This becomes a matter of best practice that you create an index based on all entries shortly before you put a view into production. Generating an index may take several hours over a large database, and you will want a fairly complete index to already be available as soon as you put the view into production.

When Couchbase Server creates an index based on a view, it will sort results based on the keys. The server will put keys in order based on factors such as 1) alphabetical order, 2) numeric order, and 3) object type or value. For information about the sort order of indexes, see Couchbase Server 2.0 Manual, Ordering.

The real-time nature of Couchbase Server means that an index can become outdated fairly quickly when new entries and updates occur. Couchbase Server generates the index when it is queried, but in the meantime more data can be added to the server and this information will not yet be part of the index. To resolve this, Couchbase SDKs and the REST API provide a stale parameter you use when you query a view. With this parameter you can indicate you will accept the most current index as it is, you want to trigger a refresh of the index and retrieve these results, or you want to retrieve the existing index as is but also trigger a refresh of the index. For instance, to query a view with the stale parameter using the Ruby SDK:

doc.recent_posts(:body => {:stale => :ok})

In this case, we query a view named recent_posts in a design document named doc. In the query we pass the parameter :stale set to the value :ok to indicate that Couchbase Server can return the most current index as it exists. For more detailed information about the stale parameter, consult the Language Reference for your SDK. For general information and underlying server operations for the stale parameter see Couchbase Server Manual 2.0, Index Updates and the Stale Parameter.

For more information and details on how and when Couchbase Server generates an index and updates an index, see Couchbase Server 2.0 Manual, View Operation .