2

It´s possible to use a dynamic value for Relation Nodes? I would like to set different Relation make for each graph on Neo4j, I think this could increase the performance of Neo4j, but I would like to know if it´s possible to use OGM on Java with dynamic value for the relations.

Thanks a lot.

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
Dante
  • 742
  • 6
  • 10

1 Answers1

2

To create relationships with dynamic types you can install APOC Procedures and use the procedure apoc.create.relationship. This procedure creates relationships with dynamic relationship type.

For example:

with "REL_TYPE" as reltype
match (n1:Node {id:1}), (n2:Node {id:2})
call apoc.create.relationship(n1, reltype,{}, n2) yield rel
return *

will create a relationship -[:REL_TYPE]- between n1 and n2.

With this approach you can pass the relationship type string as parameter to Neo4j in your Java application, then call apoc.create.relationship.

Bruno Peres
  • 15,845
  • 5
  • 53
  • 89
  • But this implementation I will need to avoid to use of OGM, that´s correct? Using OGM this dynamic relation type will not be possible, correct? I check all documentation and I don´t found anything. Do you already use the relation dynamic type? This make the Neo4J be faster for large Graphs? – Dante Feb 09 '18 at 13:15
  • @Dante No, you don't need to avoid the use of OGM. APOC procedures is a library of procedures for Neo4j database. There is no relation with your Java or OGM code. Why are you trying to create dynamic relationship types? What are your use case? – Bruno Peres Feb 09 '18 at 13:20
  • In our scenario we have more then one graph in the same Neo4J instance, where each graph has on root Node and unlimited children´s, who can have more children´s and so on. So we made a mapping using recursion where I have the Node pointing to the Edge and the Edge pointing to the Node. In this scenario all edges has the same type, but for each graph I would like the define a unique type, to optimize the cypher queries. (I really not sure if this approache will bring optimization) – Dante Feb 09 '18 at 15:43
  • @Dante Let us continue this discussion [on chat](https://chat.stackoverflow.com/rooms/164843/room-for-bruno-peres-and-dante). – Bruno Peres Feb 09 '18 at 15:46
  • 1
    Well that´s possible to, but we discuss on chat I think I could not improve my queries using this approach. Thanks for help. – Dante Feb 09 '18 at 16:51