0

I'm trying to out how to exclude nodes from a query. My graph consists of users, skills, skill scoring, questions and endo

  • user has skills
  • skill has scorings in relation with questions ((skill)-->(scorings)-->(questions))
  • endo is a relationship for users and skills scorings ((user)-->(endos)-->(scorings))

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.

  • blue is user node
  • purple is journaled endorsement node (created at)
  • green is skill scoring node

In fact the relationship "ENDORSEMENT" has a node (journalised) which connects the skill scoring nodes

endo relationship

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

rgaidot
  • 31
  • 1
  • 3
  • Could you give an example of a question that the query fails to exclude? Perhaps a picture of your whole model where you mark a node that is returned, which shouldn't be returned? – jjaderberg Oct 06 '15 at 19:16

1 Answers1

1

Your query first says that u has :ENDO relationship from e, then that e has no relationship to u, but that can't be.

How are endo nodes connected to scorings/questions in those cases you want to exclude? Could you try something like

MATCH (u:User)-[rel1:USERS]->(s:Skill)-[rel2:SKILLS]->(k:SkillScoring)-[rel3:ANSWER]->(q:Question)
WHERE u.id = '1' AND NOT u<-[:ENDO]-()-[:??]->k

and fill in the relationship type at ?? for how the endo node (anonymous node () above) is connected?

If you want you can create an example graph at http://console.neo4j.org, that would help make your intention clear.

Also, it's fine to use backticks around labels and relationships, but you don't need to unless they contain whitespace or some other uncommon characters.

jjaderberg
  • 9,844
  • 34
  • 34