Couchbase index for variable array in query


I tried to make and run some N1QL query that find document some field is matched with element of variable array in query. but speed of the query is too slow. The query is like below.

select * from bucket where tp=‘type’ and tm between 1484618520 and 1484618615 and nm=‘name’ and checked=false and ( in [“TEST”,“TEST2”])

[“TEST”,“TEST2”] part is variable depend on condition.

I want to speedup this query.

How can I create index for this query including variable array?


Create an index with gm as the leading key.

1 Like

Hi, Geraldss.

I set the “gm” field as leading key of new index using below command.

create index new_index on bucket(gm,tp,tm,nm,checked) using gsi;

Then the query speed was totally improved.

I really appreciate your advice!


1 Like