简体   繁体   中英

Cypher query: match all the couples of nodes iff they share a relationship with a specific property

I build a very simple graph having different type of nodes and just one type of relationship, named MAPPING1TO1 . Then, each couple of nodes share the same type of relationship. MAPPING1TO1 have just one property, named EventoTag . This property is an array of strings formatted as follows: (n,m) , where n is a three or two-digit integer number, and is m a two-digit integer number. So, for example, given a generic relationship r , its property EventoTag might looks like: (001,11), (002,12), (003,13), ...

I would write a query in Cypher that returns all the couples of nodes sharing a relationship that satisfy the following condition: given a string x in input, there exists a string inside the array property EventoTag that contains x as a substring.

I tried to solve this problem with the following query:

WITH "912" AS event 
MATCH p=(a)-[r]->(b)
WHERE ALL(item in r.EventoTag WHERE SUBSTRING(item,0,4) CONTAINS event)
RETURN p

The query "works", but takes too much. I have got relationships that are not right, ie does not satisfy the condition above. To make an example, look the following image of the result:

在此处输入图片说明

The selected relationship is wrong, while the others are right. It is wrong because it does not satisfy the condition (its EventoTag property does not contain the substring "912"), but still it is taken in the final result, and I don't understand why.

Can you help me? Thank you.

This is likely due to the Neo4j Browser feature that takes all the nodes returned by a query, and finds and fills in all the relationships that exist between them (regardless of whether you returned those relationships or not).

From the Browser Settings (gear icon in the lower left), scroll to the bottom and uncheck "Connect result nodes". If you re-run your query most likely the relationship will not be returned.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM