# Cypher query giving back multiple paths connecting the given multiple nodes (more than 2)

**URL:** <https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559>\
**Category:** Procedures & APOC\
**Tags:** cypher\
**Created:** [March 17, 2022, 5:12pm UTC](https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559 "2022-03-17T17:12:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rakesh](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rakesh/32/21445_2.png) [@rakesh](https://community.neo4j.com/u/rakesh)\
**Post date:** [March 17, 2022, 5:12pm UTC](https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559/1 "2022-03-17T17:12:45Z")

</div>

Hi All,

I'm new to Cypher queries and I'm looking for a query which would return all the paths connecting given multiple nodes. I found below algorithm in one of the old code and trying to understand what it's doing. Is there a page which explain how would these algorithms work? I looked around and found nothing to give more info about what are the parameters or fields would do in the below algorithm.

**Example:**  **Given Nodes:** A, B, C, D **Possible Paths:** A-\>B-\>C-\>D, A-\>F-\>B-\>C-\>E-\>D

**Old Algo I found**

```auto
WITH DISTINCT z, a CALL algo.kShortestPaths.stream(a, z, 5, 'mileage', 
	{
		nodeQuery:'MATCH (n:EquipmentNode) RETURN id(n) AS id ', 
		relationshipQuery:'MATCH p = (n:EquipmentNode)-[r:CONNECTED_TO]-(m:EquipmentNode)
			WHERE ALL ( Q IN relationships(p)
			WHERE Q.totalChannels > 0 AND (Q.totalChannelsUsed < Q.totalChannels) )
			RETURN id(n) AS source, id(m) AS target, r.mileage AS weight, r.trailName AS linkName, r.networkId AS linkNetworkId ', 
		maxDepth:75, 
		direction:'BOTH', 
		defaultValue:0.0, 
		write: false , 
		graph:'cypher', 
		path: true
	}
) YIELD path, index, nodeIds, costs

```

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [March 19, 2022, 8:19am UTC](https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559/2 "2022-03-19T08:19:27Z")

</div>

Hello @rakesh 🙂

I suppose you are using Neo4j 3.5 since algo.\* was used by the old plugin [Graph Algortihms](https://github.com/neo4j-contrib/neo4j-graph-algorithms). Since Neo4j 4.0, the plugin became [Graph Data Science](https://neo4j.com/docs/graph-data-science/current/algorithms/) (GDS) library. [Here](https://neo4j.com/docs/graph-data-science/current/algorithms/yens/) is the latest documentation for this algorithm. You can also use this [page](https://neo4j.com/docs/graph-data-science/1.1/appendix-b/) to get more information about old configurations. You should upgrade Neo4j to at least version 4 since the support is almost over.

Regards,  
Cobra

---

<div class="post-metadata">

**Author:** ![rakesh](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/rakesh/32/21445_2.png) [@rakesh](https://community.neo4j.com/u/rakesh)\
**Post date:** [April 7, 2022, 8:13pm UTC](https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559/3 "2022-04-07T20:13:05Z")

</div>

Thanks @cobra! I will take a look at it. The above part is giving timeout in some searches so any pointers why that is happening?

**error I get:** Neo.ClientError.Transaction.TransactionTimedOut

---

<div class="post-metadata">

**Author:** ![Cobra](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/cobra/32/35243_2.png) [@Cobra](https://community.neo4j.com/u/Cobra)\
**Post date:** [April 7, 2022, 9:06pm UTC](https://community.neo4j.com/t/cypher-query-giving-back-multiple-paths-connecting-the-given-multiple-nodes-more-than-2/53559/4 "2022-04-07T21:06:58Z")

</div>

The request may have taken too long, try to increase the RAM allocated to the database. Have a look at [neo4j-admin memrec](https://neo4j.com/docs/operations-manual/current/tools/neo4j-admin/neo4j-admin-memrec/).
