quelopes
quelopes

Reputation: 121

neo4j subtract elements of a path

I'm trying use this query in Cypher(Neo4):

MATCH p=(n:BP)-[:Selected]-(g:MOL)-[:Selected]-(e:BP) WHERE n.NameExp='Bos_RM' AND e.NameExp='Jac_RM' AND NONE(x IN nodes(p) WHERE x.NameExp='Jac_AGM' OR x.NameExp='Bos_SM')  RETURN n,e,g limit 100

That is, I would like exclude some nodes in path(p) that have properties 'Jac_AGM' and 'Jac_SM'. I'm using Neo4j version 2.1.3.

Thanks! Best wishes, R.

Upvotes: 0

Views: 273

Answers (2)

ulkas
ulkas

Reputation: 5918

there is also an explicit option to filter nodes in the collection p:

MATCH p=(n:BP)-[:Selected]-(g:MOL)-[:Selected]-(e:BP)
WITH FILTER(x IN nodes(p): x.NameExp NOT IN ['Jac_AGM','Bos_SM']) AS pp, n, e
WHERE n.NameExp='Bos_RM' AND e.NameExp='Jac_RM'
RETURN n,e,g limit 100

source

Upvotes: 0

Sumeet Sharma
Sumeet Sharma

Reputation: 2583

According to your query, you have already mentioned the NameExp attrib values for n and e Nodes. So its evident the nodes with the given names that you wish to be not included are among the set of g:MOL labeled nodes which you can be simply eliminated like below...

MATCH p=(n:BP)-[:Selected]-(g:MOL)-[:Selected]-(e:BP) 
WHERE n.NameExp='Bos_RM' AND e.NameExp='Jac_RM' 
AND NOT g.NameExp IN ['Jac_AGM','Jac_SM']
RETURN n,e,g limit 100

Upvotes: 1

Related Questions