I have a full graph that has the following relationships:
- HAS
- OF
- REQUIRE
I am trying to generate a subgraph using the following query but it always ends up showing duplicate relations for both OF and HAS relationships.
MATCH (fe:FEATURE)-->+(t:THREAT)-->+(g:GAP)
MATCH (g)<--+(fa:FACT)
MATCH (g)-->+(s:SCENARIO) // Match SCENARIO connected to GAP
MATCH (fa)<--+(d:DATA) // Match DATA connected to FACT
WHERE fe.key="Test_S3 Storage"
WITH DISTINCT fe, t, g, fa, s, d
WITH collect(DISTINCT [fe, t]) AS hases,
collect(DISTINCT [t, g]) AS threat_gaps,
collect(DISTINCT [fa, g]) AS requireses,
collect(DISTINCT [s, g]) AS scenarioes, // Collect scenarios
collect(DISTINCT [d, fa]) AS datas // Collect data
WITH
COLLECT {
UNWIND hases AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], 'HAS', {}, pair[1]),
pair[1]
] AS tuple
} +
COLLECT {
UNWIND threat_gaps AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], 'HAS', {}, pair[1]),
pair[1]
] AS tuple
} +
COLLECT {
UNWIND requireses AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], 'REQUIRE', {}, pair[1]),
pair[1]
] AS tuple
} +
COLLECT {
UNWIND scenarioes AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], 'HAS', {}, pair[1]),
pair[1]
] AS tuple
} +
COLLECT {
UNWIND datas AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], 'OF', {}, pair[1]),
pair[1]
] AS tuple
} AS tuples
UNWIND tuples AS tuple
RETURN DISTINCT tuple[0], tuple[1], tuple[2]
Here is the graph produced by this query
I have another version of the same query that included fewer nodes. Here it is: MATCH (fe:FEATURE)–>+(t:THREAT)–>+(g:GAP)
MATCH (g)<–+(fa:FACT)
where g.key=”attemp_post_authen_functions_gap_UP”
WITH collect(DISTINCT [fe, t]) + collect(DISTINCT [t, g]) AS hases,
collect(DISTINCT [fa, g]) AS requireses
WITH
COLLECT {
WITH hases
UNWIND hases AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], ‘HAS’, {}, pair1),
pair1
] AS tuple
} +
COLLECT {
WITH requireses
UNWIND requireses AS pair
RETURN [
pair[0],
apoc.create.vRelationship(pair[0], ‘REQUIRE’, {}, pair1),
pair1
] AS tuple
} AS tuples
UNWIND tuples AS tuple
RETURN tuple[0], tuple1, tuple2
Here is the graph produced
I am not getting an idea why my relationships are being duplicated.