# Source - Target - Path finding

**URL:** <https://community.neo4j.com/t/source-target-path-finding/59041>\
**Category:** General\
**Tags:** migrated\
**Created:** [November 23, 2022, 12:22pm UTC](https://community.neo4j.com/t/source-target-path-finding/59041 "2022-11-23T12:22:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chiara](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/chiara/32/27943_2.png) [@Chiara](https://community.neo4j.com/u/Chiara)\
**Post date:** [November 23, 2022, 12:22pm UTC](https://community.neo4j.com/t/source-target-path-finding/59041/1 "2022-11-23T12:22:23Z")

</div>

Dear All,

I am new to neo4j. I am using it to store strongly related biological data (nodes are biological entities, edges are connecting verbs of two entities). I have implemented a python Panel User Interface through which Users can search the database based on queries i have implemented. One of the search options is source-target path finding. I am currently using the Dijkstra algorithm from the GDS library. My edges are directed and i do not have weights. My question is the following: Is it possible to get the edge properties from the edges that connect the nodes in the path as return values as well? Because the edge properties yield important information and i would like to visualise the path as well with matplotlib. My current query is this:

MATCH (source:Entity {name: $source}), (target:Entity {name: $target})

CALL gds.shortestPath.dijkstra.stream('Knowledge1', {

sourceNode: source,

targetNode: target })

YIELD index, sourceNode, targetNode, nodeIds, path

RETURN

index,

gds.util.asNode(sourceNode).name AS sourceNodeName,

gds.util.asNode(targetNode).name AS targetNodeName,

[nodeId IN nodeIds | gds.util.asNode(nodeId).name] AS nodeNames

ORDER BY index

Thank you in advance

---

<div class="post-metadata">

**Author:** ![Chiara](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/chiara/32/27943_2.png) [@Chiara](https://community.neo4j.com/u/Chiara)\
**Post date:** [November 23, 2022, 2:07pm UTC](https://community.neo4j.com/t/source-target-path-finding/59041/2 "2022-11-23T14:07:13Z")

</div>

Thank you, I am getting indeed a list of relationships when adding

'relationships(path) as rel' however I was imagining to get a list of the connector verbs, but instead i am getting a list that looks like this: '[(cost), (cost)]'

To the second part, could you elaborate on how get the properties. I am from a python background so I would tackle this with a for loop, is this possible with Cypher as well?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 23, 2022, 1:24pm UTC](https://community.neo4j.com/t/source-target-path-finding/59041/3 "2022-11-23T13:24:08Z")

</div>

You can get the relationships from a path ‘p’ from ‘relationships(p)’. This will be a list. For each relationship ‘x’ in the list, you can get its properties from ‘properties(x)’.

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [November 23, 2022, 2:20pm UTC](https://community.neo4j.com/t/source-target-path-finding/59041/4 "2022-11-23T14:20:41Z")

</div>

A relationship object has a startNode, an endNide, properties, a type, and an id. All of these are accessible via methods.

The easiest method to extract attributes from a list into a new list is with list comprehension. It allows you to interate through all list elements, apply an optional filter predicate, and apply an optional transformation. The result is a new list. Your current query is using list comprehension to extract the nodeNames. The following will give you a list of the properties from each relationship in ‘path’. Each relationship’s properties is a map, so you will get a list of maps.

[x in relationships(path) | properties(x)]

[https://neo4j.com/docs/cypher-manual/current/syntax/lists/#cypher-list-comprehension](https://neo4j.com/docs/cypher-manual/current/syntax/lists/#cypher-list-comprehension)
