Return a Binary tree with relationships


I am testing out a POC in neo4j to see if it would fit my use. So far so good. I am trying to build a sales engine that stores the sellers in the form of a binary tree as in the figure:

The each node has a LEFT and RIGHT relationship.
Given a start node, I need to fetch the entire subtree below that node in both LEFT and RIGHT directions up to a certain depth of 15. These returned nodes are for the purpose of being rendered in a webpage, so a nested JSON would be optimal for that.

Currently, I am trying to use a Cypher with APOC approach, as follows:

MATCH path=(d1:Distributor)-[:LEFT|RIGHT*1..3]->(d2)
WHERE = 'Althaf'
WITH COLLECT(path) AS paths
CALL apoc.convert.toTree(paths) YIELD value RETURN value

However, the query returns the following error:

Failed to invoke procedure apoc.convert.toTree: Caused by: java.lang.ClassCastException: class java.lang.String cannot be cast to class java.util.List (java.lang.String and java.util.List are in module java.base of loader 'bootstrap')

Is there a stacktrace in debug.log ?

There is no StackTrace in the debug log.

Can you provide a minimal dataset to reproduce this?

Maybe if could you explain a bit more your goal. But this seems to be a binary tree from which you wish to pull values that are the tree below (and including? or not?) the "root" - i..e, the node you want to descend the tree from. So, maybe you don't need the apoc. Here's an idea...

//this can return the tree to a depth below some root
match (left:Distributor)<-[:LEFT|RIGHT1..n]-(root:Distributor {name:'root'})-[:RIGHT|LEFT1..n]->(right:Distributor)
return root, l,r

//and this the unique values
match (l:D)<-[:L|R1..2]-(root:Dist {name:'root'})-[:R|L1..2]->(r:D)
return distinct r as answer
match (l:D)<-[:L|R1..2]-(root:Dist {name:'root'})-[:R|L1..2]->(r:D)
return distinct l as answer
match (l:D)<-[:L|R1..2]-(root:Dist {name:'root'})-[:R|L1..2]->(r:D)
return distinct r as answer

//this pic shows my bi-tree.