Finding Common Node for given two nodes in neo4j through java

369 views Asked by At

I am developing a Question Answering application using Neo4j in Java. For that I need to find intermediate nodes between given two nodes through any relationship.

For Example given Graph:

A - x -> C
B - y -> C

Therefore if given [A,B] nodes, the output should be [C], because it is connected to both A and B through relationship x and y respectively. Is this possible using Java driver of neo4j.

Thanks

1

There are 1 answers

2
Mouse Reeve On BEST ANSWER

If A and B have ids 1 and 2, the cypher query you want looks something like:

MATCH A -- C -- B
WHERE id(A)=1 AND id(B)=2
RETURN C

Make this query from your Java setup and you should be good to go