N1QL Joins issue

You need to do two things to make this work. First, change the “orderId” values to strings. The system is expecting the values used as keys to be strings.

Like this:
doc 4
{
“docType”:“orderDetails”,
“orderId”: “2”,
“orderItems” : [
{“itemName”:“item3”},
{“itemName”:“item4”},
{“itemName”:“item5”}
]
}

Second, reverse the order of the join, like this:
select * from devl_test as orderDets join devl_test as orders on keys orderDets.orderId
where orders.docType = “orders” and orderDets.docType = “orderDetails”

Finally, note that the join is on the key values of the documents, not the “docId” value in the documents. The design you have implies that the key of the first document is exactly “1” (without the quotes).