Covering index not working

I have the following query:

SELECT META().id _ID, META().cas _CAS,
    a, b, c,
    d, e,
    f, g
  FROM myBucket
  WHERE documentType = "myDocType"
    AND d IS NOT NULL

And I created this index:

CREATE INDEX abc ON myBucket(META().id, META().cas,
          a, b, c,
          d, e,
          f, g, documentType)

But when I run an EXPLAIN the index is not taken into account. I tried with USE INDEX and no effect either.

What am I missing? What are the general rules to define a covering index? (Note: My project uses v4.1).

Does it work if you remove META().id and META().cas from both the index and the query?

I tried and it doesn’t work either.

Ok, now I see one problem. Please move documentType and d to the beginning of the index.

Thanks! It worked both adding and not adding the cas and id to the index. I decided to keep the version including cas and id

1 Like