I have a mulitgraph with mulitple relationships between nodes. I try to make a Cypher query that returns nodes connected by two relationships with different properties:
The node with label Mirna
is connected to Gene
with the REGULATES
relationship. I'd like to return all Mirna
and Gene
nodes that are connected by two REGULATES
with the source
properties first_db
and second_db
.
Here is what I tried: http://gist.neo4j.org/?4fddc897b30ef7aa4732
This works but it's very slow for large data sets. I guess because I match too much in the beginning:
MATCH (m:Mirna)-[r:REGULATES]->(g:Gene)
WITH m,g, collect(r.source) AS source
WHERE 'first_db' IN source AND 'second_db' IN source
RETURN m,g
This executes faster and gives the same results for toy data:
MATCH (m:Mirna)-[r:REGULATES { source: 'first_db' }]->(g:Gene),
(m:Mirna)-[r2:REGULATES { source: 'second_db' }]->(g:Gene)
RETURN m,g,r,r2
But is this safe and does Cypher always understand that I want two relationships between the same nodes? Is there another more efficient/elegant way to query for multiple relationships?
(a)-[r1]-(b)-[r2]-(a)
, though I'm not sure about the difference without profiling). Is this a kind of certainty estimation? I.e. "at least two authorities say that x, so probably it's true that x" kind of thing? – jjaderbergGene
is regulated, I conclude that it's more true ;) – Martin Preusse