1

I know the question above is a bit vague, but if I was more specific it wouldn't have fit in the title space. I am a bit unfamiliar with neo4j and cypher, but I think I am getting it. The problem I am having though is with two nodes I am trying to relate using a (:WRITTEN_BY) relation. The syntax I am using is this:

MATCH (d:Document), (p:Person) 
WHERE d.DocID = 'P-267-b' AND  p.PersonName = 'Billy Bob' 
CREATE (d)-[r:SIGNED_BY]->(p)
RETURN r

This doesn't cause any errors, but it doesn't return anything either. I already created the nodes that are used here, but when I use this code, no relation is actually created as far as I can tell. What am I doing wrong here? I have seen similar problems, but the solutions that were suggested didn't work for mine.

cluemein
  • 884
  • 13
  • 27
  • 1
    did you checked if the nodes are found by neo4j ? `MATCH (d:Document), (p:Person) WHERE d.DocID = 'P-267-b' AND p.PersonName = 'Billy Bob' RETURN p, d` – Christophe Willemsen Jun 23 '15 at 20:07
  • Huh, if I search for the nodes separately, they are returned. If I use the match, none are returned. Starting to think I may have been supposed to have had a matching property, where Document had signature, and matched signature with PersonName. Thought you didn't need to do that though for neo4j, that you could relate them without having the same values in a property. – cluemein Jun 23 '15 at 20:23
  • what do you mean if you search separately, 2 distinct match statements ? – Christophe Willemsen Jun 23 '15 at 20:24
  • If I do MATCH (d:Document) WHERE d.DocID='P-267-b' RETURN d, it returns the document. And then if I do the same with Person, it returns the person. But not together. – cluemein Jun 23 '15 at 20:27
  • you can then do 2 matchs and create the relationship – Christophe Willemsen Jun 23 '15 at 20:27
  • One other issue. It returns a duplicate in both cases if I do the single match. – cluemein Jun 23 '15 at 20:29
  • no it doesnt, that kind of match is called cartesian product, it is normal behavior – Christophe Willemsen Jun 23 '15 at 20:29
  • Are you saying that I need to relate the return statements and not the nodes? – cluemein Jun 23 '15 at 20:31
  • no, you can just do : MATCH (p:Person) WHERE xxx MATCH (d:Document) WHERE xxx CREATE (d)-[:SIGNED_BY]->(p) – Christophe Willemsen Jun 23 '15 at 20:32
  • but your first query should work normally, I should check with a dev db – Christophe Willemsen Jun 23 '15 at 20:33
  • Still returning 0 rows. As I said, do I need to have corresponding properties in each node, where a property in the Document node has an equal value to a property in the Person node? Or is the problem something else? – cluemein Jun 23 '15 at 20:39

1 Answers1

3

Try this if nodes are created then this query should work. Be careful with property names and label names because Cypher query is case sensitive. The first statement matches the nodes and second statement creates relation between document and person nodes.

MATCH (d:Document {docID:"P-267-b"}), (p:Person {personName:"Billy Bob"}) 
CREATE (d)-[r:SIGNED_BY]->(p)
RETURN r
asfandahmed1
  • 462
  • 5
  • 23
  • Still returning 0 rows only. – cluemein Jun 23 '15 at 21:56
  • Actually, I did what you suggested but changed the capitilizations of DocID to docID, and PersonName to personName, and that made it work thanks! – cluemein Jun 23 '15 at 22:01
  • 1
    In Neo4j all property-names, relationship-types and labels are **case sensitive**!! – Michael Hunger Jun 23 '15 at 23:35
  • @cluemein, case sensitivity was the real reason for your code returning 0 rows. – asfandahmed1 Jun 24 '15 at 14:25
  • yea. I thought I had it right, but overlooked somethings :P. That said, the simplified syntax helped me notice the problem. – cluemein Jun 24 '15 at 18:31
  • 1
    I asked, what am I doing wrong here? The correct answer from a 3rd person perspective: Make sure you are getting the cases right. Neo4j and Cypher are case sensitive. Otherwise, it should be working. – cluemein Jun 24 '15 at 18:40