I have two classes and one edge:
Product
Parameter
ProductHasParameter
with a property value
Question: How to find all Product
that have 2 edges ProductHasParameter
:
value
=<SOME_VALUE_1> to Parameter
with @rid=1
ANDvalue
=<SOME_VALUE_2> to Parameter
with @rid=2?
Example:
Question: Which Products
have Color=red AND price=1000$?
In other words: Which vertexes of class Product
have 2 edges ProductHasParameter
:
value
=red to Parameter
with @rid=8
ANDvalue
=1000$ to Parameters
with @rid=12?
Note: There is a Product with @rid=2 that doesn't have any edges at all.
I expect to get only Product with @rid=1.
In Cypher, i can write the query like this:
MATCH (prd:Product)-[hasParameterColor:ProductHasParameter]->(paramColor:Parameter {@rid:"8"})
MATCH (prd:Product)-[hasParameterPrice:ProductHasParameter]->(paramPrice:Parameter {@rid:"12"})
WHERE hasParameterColor.value="red" AND hasParameterPrice.value="1000$"
RETURN pr
Try the below:
MATCH {class: ProductHasParameter, where:(value=1000)}.outV().outE('ProductHasParameter'){where:(value='red')}.outV(){as: cars} RETURN expand(cars);
MATCH {class: ProductHasParameter, where:(value=1000)} selects all ProductHasParameter edges with value 1000 (filters out any other value other than 1000)
.outV() selects all the out vertices of the edges (cars) which implies card whose value is 1000 (can be of any color)
.outE('ProductHasParameter'){where:(value='red')} selects all the out ProductHasParameter edges from the vertices (cars) that has value red, the out vertices of these edges will have value as 1000 and color as red
.outV(){as: cars} selects the vertices back (cars)
I have not tested the query so cannot say if it works but the above thought process should filter out the cars you requires.