简体   繁体   中英

Neo4j - Cypher node and relationship relation

I have the following query:

MATCH (dg:DecisionGroup)-[:CONTAINS]->(childD:Decision) 
WHERE dg.id = {decisionGroupId} 
MATCH (filterCharacteristic1:Characteristic) 
WHERE filterCharacteristic1.id = 1 
WITH dg, filterCharacteristic1 
CALL apoc.index.between(childD,'HAS_VALUE_ON',filterCharacteristic1,'(value:(10))') YIELD rel 
WITH DISTINCT rel, childD, dg 
MATCH (childD)-(rel)  // here I need to go further only with 'childD' nodes that have relationship with 'rel'(match `apoc.index.between` predicate)

As you may see from the query above - at the end I'm trying to filter childD nodes that have the relationship with rel but I don't know how to describe it in Cypher. Something like (childD)-(rel) or (childD)-[rel] doesn't work and leads to the error. Please help

You need to look for a match pattern and compare the relationship:

...
WITH DISTINCT rel, childD, dg 
MATCH (childD)-[tmp]-() WHERE tmp = rel
RETURN rel, child, dg

Or you can compare directly:

...
WITH DISTINCT rel, childD, dg, startNode(rel) AS sRel, endNode(rel) AS eRel 
WHERE (childD)--(sRel) OR (childD)--(eRel)
RETURN rel, child, dg

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM