1

I have the following sample document:

{
    “_class”: “some.package.Class”,
    “creationTime”: 1234567890,
    “title”: “title of element”,
    “tags”: [ “tag1”, “tag2”, “tag3” ]
}

I now want to query all elements which contain given 2 tags with:

SELECT * FROM bucket WHERE _class = “some.package.Class”
AND (EVERY t IN [“tag1”, “tag2”] SATISFIES t IN tags END) LIMIT 16

I tried to create an index for this query with:

CREATE INDEX some_idx_title ON bucket((distinct (array k for k in tags end))) 
WHERE (_class = “some.package.Class”)

But on explaining the select query it does not show up.

How do I have to create the index for this query?

1 Answer 1

1

The basic answer is that you can't. Array indexes as currently implemented can not satisfy predicates of type EVERY. They can only be used for predicates of type ANY and ANY AND EVERY.

For more information about how to specify array indexes and what predicates they can be used for, consult this reference:

https://developer.couchbase.com/documentation/server/current/n1ql/n1ql-language-reference/indexing-arrays.html

(This exact question is also answered at somewhat greater length in another forum.)

Sign up to request clarification or add additional context in comments.

1 Comment

Here is where I asked the same question and got an answer which solves my problem: forums.couchbase.com/t/how-to-correctly-create-array-index/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.