I'm trying to out how to exclude nodes from a query. My graph consists of users, skills, skill scoring, questions and endo
I would like to find all question for user, but exclude those questions who user has already endo relationship
I thought I could do :
MATCH (u:`User`),
u<-[rel1:`USERS`]-(s:`Skill`),
s-[rel2:`SKILLS`]->(k:`SkillScoring`),
k-[rel3:`ANSWER`]->(q:`Question`),
u<-[rel4:`ENDO`]-(e:`Endo`)
WHERE NOT((e)-->(u)) AND (u.id='1')
RETURN u, e, k, q
UPDATE:
endo nodes are connected like this.
In fact the relationship "ENDORSEMENT" has a node (journalised) which connects the skill scoring nodes
UPDATE:
When I execute this query, it returns me the question in connection with the user
MATCH (u:User),
u<-[rel1:USERS]-(s:SoftSkill),
s-[rel2:SOFT_SKILLS]->(k:SkillScoring),
k-[rel3:ANSWER]->(q:Question),
u<-[:ENDO]-()<-[:ENDO]->(k)
WHERE u.id='1'
RETURN q, u
by cons when I execute this query to exclude the question, the query returns me questions but also question that I don't want
MATCH (u:User),
u<-[rel1:USERS]-(s:SoftSkill),
s-[rel2:SOFT_SKILLS]->(k:SkillScoring),
k-[rel3:ANSWER]->(q:Question)
WHERE u.id='1' AND NOT u<-[:ENDO]-()<-[:ENDO]->(k)
RETURN q, u
What's wrong? Any suggestions?
Thanks
答案 0 :(得分:1)
您的查询首先说明u
与:ENDO
之间存在e
关系,然后e
与u
没有任何关系,但这可以&#39}是的。
在您要排除的情况下,endo节点如何连接到scorings / questions?你可以试试像
这样的东西MATCH (u:User)-[rel1:USERS]->(s:Skill)-[rel2:SKILLS]->(k:SkillScoring)-[rel3:ANSWER]->(q:Question)
WHERE u.id = '1' AND NOT u<-[:ENDO]-()-[:??]->k
并在??
处填写关于endo节点(上面的匿名节点()
)如何连接的关系类型?
如果您愿意,可以在http://console.neo4j.org创建示例图表,这有助于明确您的意图。
此外,在标签和关系周围使用反引号也没关系,但除非它们包含空格或其他一些不常见的字符,否则你不需要。