How to get first 10 records from an array in a couchbase document


#1

SELECT ARRAY_DISTINCT ( ARRAY_FLATTEN(ARRAY_AGG(ARRAY tag for tag IN tags WHEN CONTAINS(LOWER(tag),“bird”)END),2 )) tags
FROM content
WHERE ANY tag IN tags SATISFIES ( ANY ae IN SUFFIXES(LOWER(tag)) SATISFIES ae
LIKE “bird%” END) END
AND type = “PUBLICIMAGE” limit 10;

As I am using the above query, I am getting an array called tags with 500 elements inside.I am expecting first 10 elements only of the array.How to query it?

expected result:
[
{
“tags”: [
“Sword-billed hummingbird”,
“Red-tailed tropicbird ( Phaethon rubricauda)”,
“Melodious blackbird”,
“Karyotype for a Female bird”,
“bluebird”,
“Noisy scrub-bird”,
“Crested bellbird”,
“Australian regent bowerbird”,
“Olive-bellied sunbird”,
“Rufous-tailed hummingbird ( Amazilia tzacatl)”
]
}]


#2
SELECT  RAW ARRAY_DISTINCT(ARRAY_FLATTEN(ARRAY_AGG(ARRAY tag FOR tag IN tags WHEN CONTAINS(LOWER(tag), "bird") END),2))[0:10]
FROM content
WHERE ANY tag IN tags SATISFIES ( ANY ae IN SUFFIXES(LOWER(tag)) SATISFIES ae
LIKE "bird%" END) END
AND type = "PUBLICIMAGE";

OR

SELECT  RAW t
FROM content AS c
UNNEST c.tags AS t
WHERE ANY tag IN c.tags SATISFIES ( ANY ae IN SUFFIXES(LOWER(tag)) SATISFIES ae
LIKE "bird%" END) END AND CONTAINS(LOWER(t), "bird")
AND c.type = "PUBLICIMAGE"
GROUP BY t
ORDER BY t
LIMIT 10;