shre2306
shre2306

Reputation: 63

Write undirected relationships/edges in Neo4j using Spark Connector

I am working with Neo4j to load my nodes and relationships into Neo4j using the Spark Connector. Currently the relationships that I am creating has by default a direction, is there any method to write the relationships/edges without direction (undirected edges).

Code to load the directed relationship using spark connector:

df.format('org.neo4j.spark.DataSource')
 .mode('overwrite')
 .option('relationship', 'CONTAINS')
 .option('relationship.save.strategy', 'keys')
 .option('relationship.source.labels', ':Product')
 .option('relationship.source.save.mode', 'Match')
 .option('relationship.source.node.keys', 'productID:id')
 .option('relationship.target.labels', ':Order')
 .option('relationship.target.save.mode', 'Match')
 .option('relationship.target.node.keys', 'orderID:id')
 .option('relationship.properties', 'quantity:quantityOrdered')
 .save())

This will create an edge from Product node to Order node.

(Product) - [r:CONTAINS] -> (Order)

Is there any method using spark or using Cypher query (after loading the edges) to create undirected relationships between 2 nodes.

thanks

Upvotes: 0

Views: 196

Answers (1)

user4417327
user4417327

Reputation:

Neo4j does not support undirected relationships. Though you can omit the direction during queries, e.g. MATCH (NodeA)--(NodeB) or MATCH (NodeA)-[SOME_RELATION]-(NodeB), you really shouldn't, as it will decrease query performance.

Upvotes: 2

Related Questions