How to write Nested N1ql Query


#1

select * from content WHERE _type=“question” and (ANY grd IN IFMISSINGORNULL([‘Grade1’,‘Grade2’],[ ]) SATISFIES grd = grade END OR
ANY sub IN IFMISSINGORNULL([‘Mathematics_g1’,‘Mathematics_g2’],[ ]) SATISFIES sub =subject END OR
ANY top IN IFMISSINGORNULL([‘Mathematics_g1_t1’],[ ]) SATISFIES top =topic END OR
ANY dif IN IFMISSINGORNULL([‘Medium’],[ ]) SATISFIES dif=difficulty END OR
ANY mrk IN IFMISSINGORNULL([‘1’,‘10’],[ ]) SATISFIES mrk=marksVal END OR
ANY tle IN IFMISSINGORNULL([ ],[ ]) SATISFIES tle =title END OR
ANY que IN IFMISSINGORNULL([‘fillup’],[ ]) SATISFIES que =question END)

The above query returns result but doesn’t serve my purpose.

Senario:

1.I need records which matches value in grade field(i.e “Grade1” ,“Grade2”).
2.From point 1 result I wanna filter records which matches values in subject.
3.From point 2 result I need to filter records which matches values in topic.
and so on.

Real Life Example:
I wanna buy a shoes from Amazon.
So the follwing way I will search shoes for me.

men->footware->Formal shoes->Size 7->black color.
which gives me 30 records.

How can I frame my query so that I will Get the deesired result after I filter all the fields.
In this case the Hirerchy will be like below.
GRADE
SUBJECT
TOPIC
DIFFICULTY
MARKS
TITLE
QUESTION


#2
SELECT *
FROM content
WHERE _type = "question"
      AND grade IN ["Grade1","Grade2"]
      AND subject IN ["Mathematics_g1","Mathematics_g2"]
      AND topic IN ["Mathematics_g1_t1"]
      .........
;

Add new conditions when you need.