You just need to understand what it's doing, and whether that's the right thing for your query. You need to think about the cardinality, the number of rows being processed, as this is what's causing the duplications.
In your example we can clearly see the number of entries in each list, so that helps illustrate what's going on. Remember that Cypher operations execute per row (and this is what allows UNWIND to have an iterative effect even though it's not really an iterating structure like FOREACH):
Assuming at the staring WITH that we have 1 row.
At the first UNWIND we now have entry rows x the number of list elements, so 1 x 2 = 2 rows.
The CREATE occurs, creating the pattern once for each row. 2 :DTP nodes are created, with a relationship created to each.
The with dt
does NOT alter the cardinality, you still have 2 rows, with the same dt
node for each.
The next UNWIND executes: for each of the 2 input rows, they are multiplied by the number of list elements, so 2 x 2 = 4 rows.
The CREATE executes for each row, 4 new :DTV:RDTV nodes are created.
The with dt
again does not change the cardinality, you have 4 rows with the same dt
for each.
4 rows are returned with the same dt node's uuid property as id.
If you wanted to reset the cardinality at each WITH clause, use WITH DISTINCT dt
or WITH dt, count(dt)
or a similar aggregation to ensure dt is distinct.