How to create partial index (with where condition in the index) by using Couchbase Java SDK 3.0?
I was referring the below for the com.couchbase.client.java.manager.query.QueryIndexManager & com.couchbase.client.java.manager.query.CreateQueryIndexOptions from the below link. I couldn’t see any op[tion to include where clause.
I looked at the Index manager API and I don’t see a way to specify a WHERE clause. Thanks for reporting this omission. I’ve filed JCBC-1629 to track the issue.
I’ve since learned that the omission is intentional. Apparently there are a great many options for index creation, and it was decided that the index management API should only support the most common options.
The good news is that it’s relatively easy to create an index using the Query API. (In fact, the Index Management API uses the Query API behind the scenes). Here’s the documentation for the
CREATE INDEX query command:
I feel that we should not restrict functionality in Java SDK. You can keep it in
CreateQueryIndexOptions, or make a separate function which adds
whereCondition. To keep it simple, you can ask for a String in either of the places, so that you don’t have to do a lot of pipelining.
There are two points in what you have mentioned:
- Scopes and collections are only there in 7.x that is not stable yet
- Even with 7.x inclusion, some usecases might prefer having the conditional query
- In my own usecase, I have a lot of indexes with different where conditions
- I don’t want to create different scopes and collections for each where condition
I feel it would be great if this is included in the latest release.