The WHERE following the OPTIONAL MATCH is executed along with it, so if it
doesn't ever return true, it only affects the OPTIONAL piece, and you'll
get all of the service nodes continuing on to the next part of the query.

You probably need to split it up with WITH to get the behavior you want:
START service=node:ProcessNode('*:*')
OPTIONAL MATCH service<-[:monitoring]->monitor
WITH service, monitor
WHERE "service" in service.roles
WITH service, monitor, count(monitor) as moncount
MATCH host-[:hosting]->service
WHERE moncount = 0
RETURN DISTINCT host, service
ORDER BY service.roles[0], host.designation

Wes

http://wes.skeweredrook.com/cypher-2-0-optional-match/

On Thu, Mar 27, 2014 at 5:34 PM, Alan Robertson <al...@unix.sh> wrote:

> Here's a sample Cypher query that I'm having trouble with...
>
>                START service=node:ProcessNode('*:*')
>                OPTIONAL MATCH service<-[:monitoring]->monitor
>                WHERE "service" in service.roles
>                WITH service, monitor, count(monitor) as moncount
>                MATCH host-[:hosting]->service
>                WHERE moncount = 0
>                RETURN DISTINCT host, service
>                ORDER BY service.roles[0], host.designation
>
>
> When I run this query, the results include service nodes where "service"
> is NOT in service.roles.  Sample output is below:
> servidor /usr/bin/ssh ['client']
> servidor /usr/bin/ssh ['client']
> servidor /usr/bin/pidgin ['client']
> servidor /usr/sbin/bacula-sd ['server', 'client']
> servidor /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java ['server']
> servidor /usr/bin/perl ['server']
> servidor /home/alanr/.dropbox-dist/dropbox ['server', 'client']
> servidor /usr/sbin/sshd ['server']
> servidor /usr/bin/tprintdaemon ['server']
> servidor /sbin/rpc.statd ['server']
> servidor /sbin/rpcbind ['server']
> servidor /usr/bin/skype ['server', 'client']
> servidor /usr/sbin/bacula-dir ['server', 'client']
> servidor /usr/sbin/dnsmasq ['server']
>
> The fields printed here are host.designation, service.pathname, and
> service.roles.
>
> What's up with this?  I also tried service.roles[0] = "server" instead.
> It didn't help.
>
>
>
> --
>     Alan Robertson <al...@unix.sh> - @OSSAlanR
>
> "Openness is the foundation and preservative of friendship...  Let me
> claim from you at all times your undisguised opinions." - William
> Wilberforce
>

-- 
You received this message because you are subscribed to the Google Groups 
"Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to neo4j+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to