Learning Couchbase Indexing/Views (Practical)

Hi there, I’ve been trying to learn couchbase but most of the available resources are essentially theory or overviews, and practical resources appear to be non-existent.

I’m working with 2 collections, one with 480K documents and the other has 1.5M. Server performance is about 38Kops/s. Primary indexes created for each collection.

To simplify the picture, lets say its an ecommerce site and each of the docs are skus with product data. There’s a field within each document that holds a category code, and I’m simply trying to query how many documents there are whos category code start with 3 particular digits for example. The issue im having is that the query (select count(sku) from a.b.c where substr(catcode,0,3) == 001) takes 13.7s, and there are 30 different categories that i need to fetch the same count for.

Trying to display a category tree with a count of how many skus are in each but processing time is too great.

Now, it appears that views can assist with this by basically caching and updating the result im looking for in this particular scenario. I see and understand how views can help, but i cannot find step by step instructions on how to create and test the view. I tried what i thought would work, basically the default map returning the meta.id and doc.catcode but it shows no results.

What are the best resources out there for learning how to do this from a practical standpoint? Something with before and after results, and the actual steps in between?

I’m totally ok with paying for courses to learn what i’m trying to do. I’ve learned that a few hours of learning can save dozens and dozens. So i’d like to know what the best resources are out there, and if you can help me over this little hurdle feel free to enlighten.

Thanks!

Solved with a bit of discovery. I clicked “index advisor” for my query out of curiosity and it recommended a new index. Created and built that and the query now takes 21ms - awesome!

Luckily the solution I needed was front and center, but what if it wasn’t there? I wouldnt know what to do, so i’m still very interested in recommendations for practical learning materials.

Thanks again

Hi, a quick note on views:

Views are deprecated in Couchbase Server 7.0+. Views support in Couchbase Server will be removed in a future release only when the core functionality of the View engine is covered by other services. Views will not run on the newer Magma storage engine

For learning materials, tutorials are available on our website: Developer Portal | Couchbase
We have a fairly complete documentation Couchbase Documentation | Couchbase Docs
I know some books or courses exist but have not read/taken them.

I encourage you to read on JSON Data Modeling: JSON Data Modeling: Tools + Examples to Design Model

And start modeling your data based on the queries you will have in your app.

1 Like

Luckily the solution I needed was front and center, but what if it wasn’t there?

If you could not find what you were looking for with Google, you could post your question on forums.couchbase.com . Couchbase users and staff regularly look for questions posted there.