Showing results forΒ 
Search instead forΒ 
Did you mean:Β 

Possibility to have a link pointing on a link?

Node Clone

I'm wondering if the possibility to have a link pointing on a link will be implemented in the futur ?
This would allow request as :
Creating a link pointing on a link

CREATE (n)-[l:LINK]->(m)

Matching a link pointing on a link

MATCH (o)-[:LINK_TO_LINK]->[l]

Use case :
You have a product and a tag linked to this product, you can attach customers to this link. It says : "These customers have linked this product to this tag"

Current workaround :
Give a uuid to the link between the product and the tag, then connect each customer to a node where one of the property is the uuid of the link. Create an index on the link uuid property and you are good to go.

Another workaround (less good imo)
Instead of connecting directly the product to the tag, insert a middle, anonymous node between them and connect the customers to the anonymous middle node.

Is it really useful ?
Well I know some people who have left neo4j for because of this πŸ˜•



This use case that you describe is generally called a "hyper edge".

Neo4j does not support them. So that's the simple answer. Generally the way people handle this situation is to factor out another node which represents the relationship you're trying to model. They then hang relationships off of that.

For example instead of this:

CREATE (n)-[l:LINK]->(m)

You would do this:

CREATE (n)-[:l:LINK]->(link:LinkEntity)<-[:LINK]-(m)
CREATE (link)-[:LINK_TO_LINK]->(someOtherLink)

There's a blog post on this here:

Finally -- for what it's worth, the non-support for hyperedges is intentional. They have hyperedges in RDF (sometimes referred to as "reification" in RDF) and it makes things very complicated and hard to deal with in the data model when it grows beyond trivial scale. I think you'll find that factoring out separate nodes is a cleaner way of dealing with it, and gives you more flexibility to assert metadata about your relationships as a first class nodes.

Hi Mr Allen,
thanks for your answer. As I said, I don't like using a "middle" node when I want to connect a link to a link because I think it makes the model very unclear.
I prefer things like this :

CREATE (n)-[:l:LINK{uuid:linkuuid}]->(link:LinkEntity)->(m)
CREATE (link)-[:LINK_TO_LINK]->(Pointer{uuid:linkuuid})

I don't know enough of the neo4j internals to see if this is a bad idea or not πŸ˜•

I'm not convinced by what you said about hyperlinks. Hyperlinks are edges between more than two nodes, for instance given thre nodes a, b, c, a hyperlink is written h = (a, b, c). This is a three way relationship but I think it's difficult to express things such as "this user has given this tag to this product" with this kind of object. See

I'm more interested in connection such as (a, (b, c)) and even ((a, b), (c, d)) where d is another node.

Regarding the RDF. I distinguish the model and it's implementation. For me the link you provided shows that we agree on the interest of this special kind of link in some models. From here, Neo4j provides at least two ways to implement them. I just think that a more straightforward way to implement them could be nice.

Nodes 2022
NODES 2022, Neo4j Online Education Summit

OnΒ November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.