0

Having multiple documents an structure similar to this:

{
'key1':value,
'key2':value2,
'galaxy':{
           'planets':['earth','mars','welcomebackpluto']
           'sun': 'something'
          }
}

I would like to query all the documents that have mars within the planets array in the galaxy object.

The indexes I've created haven't worked and I'm not able to query them, any idea how to?

1 Answer 1

1

Use Array indexing

CREATE INDEX ix1 ON default (DISTINCT ARRAY (DISTINCT ARRAY p FOR p IN g.planets END) FOR g IN galaxy END) WHERE type = "xyz";

SELECT d.*
FROM default AS d
WHERE d.type = "xyz" AND ANY g IN d.galaxy SATISFIES (ANY p IN g.planets SATISFIES p = "mars" END) END;

https://docs.couchbase.com/server/6.0/n1ql/n1ql-language-reference/indexing-arrays.html

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

Comments

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.