neo4j: represent object property instead of relationship in links between objects

Multi tool use
neo4j: represent object property instead of relationship in links between objects
I want to use neo4j to represent networks, in order to make nice graphics like this one:
Here is the code used so far:
CREATE (router1:Router {name:'router1', defaultgw:'192.168.123.1'})
CREATE (network1:Network {name:'network1', cidr:'192.168.123.0/24'})
CREATE (server1:Server {hostname:'server1', ip:'192.168.123.7'})
CREATE (server2:Server {hostname:'server2', ip:'192.168.123.9'})
CREATE
(router1)-[:CONNECTED_TO {}]->(network1),
(network1)-[:CONNECTED_TO {}]->(server1),
(network1)-[:CONNECTED_TO {}]->(server2)
WITH router1 AS r
MATCH (r)-[:CONNECTED_TO]->(n)-[:CONNECTED_TO]->(s) RETURN r,n,s
;
Is there a way to represent the subnet used between router and network, and the ip of the server on the link between servers and related network, instead of the appropriate but meaningless CONNECTED_TO
?
CONNECTED_TO
I have tried to define relationships as:
CREATE (router1)-[:CONNECTED_TO {'192.168.123.0/24'}]->(network1)
or
CREATE (router1)-[:CONNECTED_TO {network1.cidr}]->(network1)
with no success. Is it even possible ?
Many thanks for your help
1 Answer
1
[EDITED]
Every property needs a name. For example, cidr
:
cidr
CREATE (router1)-[:CONNECTED_TO {cidr: '192.168.123.0/24'}]->(network1)
Here is a complete query:
CREATE (router1:Router {name:'router1', defaultgw:'192.168.123.1'})
CREATE (network1:Network {name:'network1', cidr:'192.168.123.0/24'})
CREATE (server1:Server {hostname:'server1', ip:'192.168.123.7'})
CREATE (server2:Server {hostname:'server2', ip:'192.168.123.9'})
CREATE
(router1)-[:CONNECTED_TO {cidr: '192.168.123.0/24'}]->(network1),
(network1)-[:CONNECTED_TO {ip:'192.168.123.7'}]->(server1),
(network1)-[:CONNECTED_TO {ip:'192.168.123.9'}]->(server2)
WITH router1 AS r
MATCH (r)-[:CONNECTED_TO]->(n)-[:CONNECTED_TO]->(s) RETURN r,n,s
;
But adding this property to the relationship would cause storage of the property in two places -- which may be wasteful, and if the property value needed to change that would require extra effort to perform the update in multiple places. I would advise putting the property in only one place, with the decision depending on the needs of all your use cases.
WITH gw_project_router AS g MATCH p=(g)-[:CONNECTED_TO *]->(x) WHERE NOT (x)-[:CONNECTED_TO]->() RETURN p;
See my edited answer for the complete query. It works for me.
– cybersam
Jul 1 at 6:06
You're right: it works. Maybe the fact I have been adding relationships with and without properties didn't let me chose for the whole graph which property I wanted to display. Many thanks!
– philippe
Jul 1 at 10:02
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thank you for your answer, but it does not seem to work ; I have used this
WITH gw_project_router AS g MATCH p=(g)-[:CONNECTED_TO *]->(x) WHERE NOT (x)-[:CONNECTED_TO]->() RETURN p;
as query– philippe
Jun 30 at 7:24