We have a Couchbase DB and a spring boot application that interacts with it. The database has many types of documents amongst which we have order transaction documents. One of the queries is to get the Count of the number of Order transaction documents from the DB. The count of these documents in the DB is around 200 million and increasing. The query looks like the following :
SELECT COUNT(META(d).id) AS count FROM `orders` AS d WHERE META().id LIKE ':order:trx:%'
We are using the following index for this :
CREATE INDEX `idx_order_trx_meta_id` ON `orders`(meta().id) WHERE meta().id LIKE ':order:trx:%'
However this query times out even after adding an index on the bucket.
Is there a way to write efficient count queries for large document sets? Like for example use a view that keeps the count of this document or some other way?