3
(:Dot)-[:CONTAINS]->(:Dot)

Not every dot has a container and also there are no loops. Atm a dot can only be contained by one other dot. So we are basically talking about trees

Now I would like to use Neo4j to retrieve the data and return it hierarchally (by containers):

[
    {"id": 1, "containees": [
        {"id": 3},
        {"id": 4, "containees": [
            {"id": 6},
        ]},
    ]},
    {"id": 2, "containees": [
        {"id": 5}
    ]}
]

The query shouldn't use a fixed depth.

Atm I only have this, and I'm really not sure what my options are concerning iterating a path.

MATCH (d:Dot)
OPTIONAL MATCH p = d-[:CONTAINS*]->(d2:Dot)
RETURN d.id
0

1 Answer 1

2

I'm pretty sure this isn't possible currently with Cypher (somebody please correct me if I'm wrong). Cypher is good at taking subgraph matches and turning them into tables, but it doesn't do recursive-type querying.

For this sort of thing I think you'd need to work through the Java APIs directly. Either by interfacing with Java with your language of choice, or by creating an unmanaged extension to have Neo4j return the data for you in JSON (or whatever format you'd like)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.