ORDER BY extremely slow when ordering by array value

As i mentioned earlier this works on single equality, If you looking results in different format it may not able to optimize.

The following link has some details. (MB-32506 or links attached to this Issue.

SELECT b.id, {fltr[0]:fltr2[1]}.*
FROM bucket AS b
UNNEST b.answers AS a
LET fltr = [a.q, a.v]
WHERE b.type = 'record'
AND ((fltr >= ['question1'] AND fltr < [SUCCESSOR('question1')])
     OR (fltr >= ['question2'] AND fltr > [SUCCESSOR('question2')])
     OR (fltr >= ['question3'] AND fltr > [SUCCESSOR('question3')]))
ORDER BY fltr
LIMIT 30;

If you are looking the all questions in same document

CREATE INDEX ix10 ON bucket(DISTINCT ARRAY a.q FOR a IN answers END) WHERE type = 'record';

SELECT b.id, obj.*
FROM bucket AS b
LET obj = OBJECT a.q:a.v FOR a IN b.answers WHEN a.q IN [ "question1", "question2", "question3"] END
WHERE b.type = 'record'
      AND ANY a IN b.answers SATISFIES a.q IN [ "question1", "question2", "question3"] END
ORDER BY obj.`question3`;

fltr = [a.q, a.v]
Takes values : [“question1”,1] , [“question1”,2] , [“question1”,30], [“question2”,0]
a.q = “question1” means it needs 3 values (this is scalar value comparision)
Now fltr is ARRAY of 2 values. Index selection/push the values index predicate expression must match exactly with index key i.e [a.q, a.v]
As we don’t know second part of array value only knows first part we are converting equality to range of 2 values any value in second position return

(fltr >= [‘question1’] AND fltr < [SUCCESSOR(‘question1’)]

Use with caution. In 7.1 this makes much easier. As you looking your output in different format this all may not work. Use one suggested ix10 and query