Hi! I’ve created this index CREATE INDEX idx-join-bsa-trx-with-events ON BSA_TX_EVENTS (lastEvent.publicRequestKey);
and I have this query select * FROM BSA_TRANSACTION bvtpTransaction JOIN BSA_TX_EVENTS trxEvents on key (trxEvents.lastEvent.publicRequestKey) for bvtpTransaction;
select * FROM BSA_TRANSACTION bvtpTransaction JOIN BSA_TX_EVENTS trxEvents on key (trxEvents.lastEvent.publicRequestKey) for bvtpTransaction WHERE lastEvent.publicRequestKey IS NOT MISSING ;
In Flexible Schema world, we’ve to account for missing fields. So, a predicate here will enable the optimizer to chose the right index.
The query I gave had an issue. The predicate should use fully qualified attribute name.
Please try this.
select *
FROM BSA_TRANSACTION bvtpTransaction
JOIN BSA_TX_EVENTS trxEvents on key (trxEvents.lastEvent.publicRequestKey)
for bvtpTransaction
WHERE bvtpTransaction.lastEvent.publicRequestKey IS NOT MISSING ;
Both your original query and Keshav’s query are correct. You are not filtering on bvtpTransaction at all, so the left side is a full scan. Is that your intention? To query all the data? If so, you can just transpose left and right terms.
SELECT *
FROM events JOIN transaction ON KEYS event.lastEvent.publicRequestKey;
Of course it is same concept of what you provided, but you were using composite keys for some reason. Then when you query this view and provide an id as the key, both documents should come back.
You should be aware that since Views don’t do joins, the experience won’t be the same to what you’d find in a N1QL query.
The composite it’s to filter with those keys … the view that you give me works fine but I have a problem. The documents are in different buckets so I only can get one type of document no both of them.
Can I do something to retrieve document from other bucket in the view or the documents must to be in the same bucket ?
Views are per Bucket so you wouldn’t be able to create a view that covers both Buckets. This further emphasizes the power of N1QL and the effort that is being put into it in every release.
If you needed to query across buckets using views, you’d have to do multiple queries. This would all be managed in the application layer.