I want to create subquery and use keys with parent query meta().id like below:
SELECT META(category).id AS _ID,
META(category).cas AS _CAS,
category.*,
(
SELECT *
FROM default USE KEYS META(category).id
WHERE class = "com.ecommerce.inventory.model.product.Product" ) childs
FROM `default` category
WHERE category.class = "com.ecommerce.inventory.model.category.Category"
In your parent query you are getting class Category
FROM default USE KEYS META(category).id
means you are getting same document again now you looking class Product which will eliminate.
Please post sample documents relation fields and what you need.
CREATE INDEX ix1 ON default(class, parentId) WHERE class = "com.ecommerce.inventory.model.category.Category";
SELECT l.*, c AS childs
FROM default AS l
LEFT NEST default AS c
ON META(l).id = c.parentId AND c.class = "com.ecommerce.inventory.model.category.Category"
WHERE l.class = "com.ecommerce.inventory.model.category.Category"
N1QL supports correlated subquery through parent document (doesn’t support generically). If needed use JOIN /GROUP BY.
after run query i get
[
{
“code”: 3000,
“msg”: “Ambiguous reference to field r.”,
“query”: “SELECT l.*,\n r AS childs\nFROM default AS l LEFT NEST default AS c ON META(l).id = r.parentId\n AND r.class = “com.ecommerce.inventory.model.category.Category”\nWHERE l.class = “com.ecommerce.inventory.model.category.Category””
}
]