Note that there are some explanatory texts on larger screens.

plurals
  1. POOptional related paths with neo4j and cypher on a more complex MATCH statement
    primarykey
    data
    text
    <p>I have a query which is going over a graph of companies, groups, watchlists and members. See the <a href="https://gist.github.com/Jmaharman/534ee95e807aa193faf2" rel="nofollow">gist of dummy data in geoff format</a> for the data in the database. I've also setup a <a href="http://console.neo4j.org/r/vtrcct" rel="nofollow">console neo4j</a> for anyone to play with.</p> <p>The aim of the query is to get a list of groups as well as the number of members (a member is a generic term for a person or a company) that have a relationship with the group and its related watchlists.</p> <p>With the query below I'm getting the correct alert numbers but I'm missing "Empty group" because it doesn't have any members or watchlists. I've tried to make various relationships optional but it ends up getting the count of alerts wrong because it's using watchlists that are related to the group. I've tried countless ways of writing the query but just can't get around the problem.</p> <pre><code>START company=node(233), group=node:node_auto_index("_type:group") MATCH company-[:OWNS]-&gt;group-[?:LINKED_TO]-&gt;watchlist-[:WATCHING|APPOINTMENT*1..2]-member&lt;-[:WATCHING]-group RETURN group, COUNT(DISTINCT(member)) as alerts ORDER BY group.name </code></pre> <p>Ideally I'd like to make the entire path segment which connects a group to members and then onto watchlists as optional however I can't find out how to do that in the docs or it's just not possible. Is there any other way around this other than doing two queries?</p> <p>The correct results are that the groups and alerts should be:</p> <pre><code>Big Dot Coms, 1 Big Hitters, 4 Empty group, 0 Old CEOs, 1 </code></pre>
    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.
 

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