Is it possible for Neo4j to detect relationships between entities without uploading a file which containing only relationships?
When I use Neo4j, first I create nodes by upload files that contain the entities, and then create the relationship among the nodes by a file (or files) that defines the relationships between the entities. Would it be possible to have Neo4j detect the relationships without uploading the relationship file(s)? As an example, we have two entities that have already been indexed and uploaded as follows: A including: A.ID, A.Year, A.Name B including: B.ID, B.Year, B.Name Would it be possible to detect a relationship between A and B based on A.ID=B.ID AND A.Year<=B.Year?
[UPDATED]
You can do something like this:
MATCH (a:Foo), (b:Foo)
WHERE a <> b AND a.ID = b.ID AND (a.Year < b.Year OR (a.Year = b.Year AND id(a) < id(b)))
CREATE (a)-[:BAR]->(b)
Notes:
:Foo(ID)
.Foo
node to itself, we specify the a <> b
condition.a.Year <= b.Year
condition allows equal Year
values, so the same pair of Foo
nodes can be matched twice (as a/b, and as b/a). So we specify the (a.Year = b.Year AND ID(a) < ID(b))
condition to avoid creating 2 relationships between the same pair of nodes in opposite directions. The id function returns the native ID, not your ID
property.While the above query works, we don't actually need to specify the a <> b
condition as stated in Note #2, since the code mentioned in Note #3 is sufficient to enforce that condition. So, you can omit a <> b AND
from the query.