Note that there are some explanatory texts on larger screens.

plurals
  1. POCypher query to match strong two way relationship and filter by property values in Neo4j
    primarykey
    data
    text
    <p>I would like to find a subgraph in Neo4j DB with only strong two way relationships.</p> <p>Let's say the relationship is LOVES and attribute is Kisses then I would like to only find a subgraph where both sides have kissed the other more than 2 times.</p> <pre><code>START n=node(*) MATCH n-[r1:LOVES]-&gt;friend&lt;-[r2:LOVES]-n WHERE r1.Kisses &gt; 2 and r2.Kisses &gt; 2 RETURN n, friend, r1, r2 LIMIT 20 </code></pre> <p>the problem is that the query seems to run forever on a 3M node 30M relationship graph, on a 32GB RAM, quad core system with 16GB max heap for neo4j(neo4j calculator suggested 8GB).</p> <p>I suspect, there is an endless loop hiding somewhere.</p> <p>OS: Ubuntu 12.04.1 LTS server</p> <p>Soft: neo4j-community-1.8.1</p> <p>java version "1.7.0_10" (neo4j start says to use JDK6)</p> <p>Java(TM) SE Runtime Environment (build 1.7.0_10-b18)</p> <p>Java HotSpot(TM) 64-Bit Server VM (build 23.6-b04, mixed mode)</p> <p>EDIT: match is incorrect it should be </p> <pre><code>MATCH n-[r1:LOVES]-&gt;friend-[r2:LOVES]-&gt;n </code></pre> <p>UPDATE: After correcting semantics above, I am still unable to get a full result in 5 minutes.</p> <p>LOVES is the only relationship type and about 10-20% or relationships have a corresponding one going the other way. </p> <p>My ultimate goal is to find appropriate Kiss values so that I am left with &lt;100k nodes (and all appropriate LOVES relationships) and can export this subgraph.</p> <p>Here's pseudocode for algorithm for what I am trying to do:</p> <pre><code>let E be edge.list to be processed let myedgelist be empty list for e in E: if e.n1 &gt; e.n2: # so we do not look twice continue if not exist(e[n2][n1]): # this is where lookup can be a problem O(1) for hash, O(logn) for sorted, O(n) for something random) continue if e.kisses &gt; 2 and e[n2][n1].kisses &gt; 2: add e to myedgelist add e[n2][n1] to myedgelist return myedgelist </code></pre> <p>This algorithm should run at most edgecount * log(edgecount), unless there is no effective way to lookup existence of reverse relationship in neo4j, which would seem rather inconceivable.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload