0
votes

I'm a newbe with py2neo.
Trying to create a cypher statement to which includes some sort of selection like

query = 'MATCH (p:Person {name:"Alice"}) - [r] - b) RETURN p,r,b' res = Graph.run(query)
I'm getting a KeyError: 'name'

Running the same query directly in neo4j shell or web client runs successfully.

Update

I manage to run the code using the WHERE statement:
query = ('MATCH (p:Person) - [r] - b) WHERE p.name="Alice" RETURN p,r,b') res = Graph.run(query)
Is this the only option to run py2neo queries or is there a way to use the key values of the node properties?

Thank you in advance

1

1 Answers

0
votes

The second node b should be enclosed by parenthesis (). I've also created a graph object from the Graph class:

from py2neo import Graph
neo4j_config = dict(
    user="neo4j",
    password="neo4j_pwd"
)
graph = Graph(**neo4j_config)
query = 'MATCH (p:Person {name:"Alice"}) - [r] - (b) RETURN p,r,b'
res = graph.run(query)