indexing - Can I create a custom N1QL secondary index with spring-data-couchbase from within application code? -
i created global secondary index in couchbase hand running:
create index custom_index on `my-bucket`(field_name) using gsi {"nodes": ["localhost:8091"]}
i have spring boot application. there way index can automatically created spring-data-couchbase? desired behaviour follows: @ application startup, if index doesn't exist created. far read secondary index can automatically created @n1qlsecondaryindexed
indexes based on _class
field.
a warning first: not recommended couchbase support, because if 1 node in cluster down , 1 holds index, app recreate duplicate index on node, can problematic.
that's why @n1qlsecondaryindexed
thing opt-in (you have change configuration activate it).
there's no automatic , direct way of creating particular index, can access underlying sdk can within spring boot application
.
inject reference bucket
(i'm assuming you're configuring spring use my_bucket default) , use index management api on bucketmanager
:
bucket.bucketmanager().createn1qlindex("custom_index", true, false, "field_name");
the parameters method index name, ignore "index exist error", don't defer creation , fields index (as described in javadoc).
Comments
Post a Comment