0

I have a query to Neo4j through Py2neo v3 using ogm:

output = graph.run("MATCH (m:Column { name: 'code' }),(n:Column { name: 'locale_language_cd' }), p = shortestPath((m)-[rels:PART_OF*]-(n)) RETURN p").evaluate()

print(output)

This correctly does what I want it to, but the nodes are not legible

(f0b4322)-[:PART_OF]->(f86202d)<-[:PART_OF]-(a16fb7b)-[:PART_OF]->(b3562af)<-[:PART_OF]-(a7bfe43)

If I run the code again:

(b539883)-[:PART_OF]->(c83d89b)<-[:PART_OF]-(f2adac1)-[:PART_OF]->(fd469a6)<-[:PART_OF]-(e373bf4)

Here is a link to what the data looks like in Neo4j: Neo4j output with same search parameters

Every time I run the code the outputs are different, I would like the digits to be replaced with the GraphObject names (their primary key).

Tim Kralj
  • 21
  • 3

1 Answers1

0

Since you're only querying for nodes that match name=code, and name='locale_language_cd', imagine you're picking a random apple out of a really big bag of apples.. apple.. mmmm...

Each time you reach in, you're getting a different apple.
Same thing with the path. You're not asking for the 'shortestPath' or anything. You're effectively asking the database to pick the 'first path you find' between n && m.

If you want to get more consistent results, search by primary key on either node, or sort by another attribute and pick the 'first' available..

To answer the second question, instead of printing the result set, which is a 'path' object, instead, return and print the nodes.

OR, use the built in functions to iterator your results.

something like:

for x in results:
    p = x['p'] # This is the path
    print p

To see what's in p

  • Thank you for the reply, but how do I search by primary key? I have set that the __primarykey__ attribute is the name property. Shouldn't this mean I am searching by primary key already? – Tim Kralj Jul 11 '17 at 19:29
  • yes! You're already searching by the name property. (m:Column { name: 'code' })... but you're returning p.. where p is the path. Maybe I'm missing the intent of your question. – chrisfauerbach Jul 12 '17 at 21:12