problem with the match statement of neo4j and py2neo

created at 03-18-2022 views: 12


In recent projects, neo4j needs to be used to build a knowledge graph. Used py2neo instead of neo4j official api.

initialization When using it, you must first run it in Terminal

./bin/neo4j console

then run your code inside python

graph = Graph("http://localhost:7474",auth=("neo4j", "xxx")) #auth parameters account, password
graph.delete_all() # Clear first
graph.begin() # start

Then every time you create Node/Relationship and graph.merge(...), you can see the effect in the web version http://localhost:7474/browser/

match statement problem

First, I am using the latest version of neo4j (2020.06.16) and py2neo v4. First try to use the official v4 manual

matcher = NodeMatcher(graph)
node1 = matcher.match(“Person”, name=“Tom”).first()

Not work, reported an error.

Change it to this will work:

node1 = matcher.match(‘Person’).where("‘Tom’").first()


we still have a problem

That is if you want to use variables in where like

  • .where(""), this will not work! ! !
  • .where("'name1'"), this will also not work! ! !

I don't want to analyze how to escape or quote variables in quotes, so I have to write the code like this. .where("" + "'" + name1 + "'")

created at:03-18-2022
edited at: 03-20-2022: