Reputation: 107
I am querying data from MSsql server and saving it into CSVs. With those CSVs, I am modelling data into Neo4j. But Mssql database updates regularly. So,also wants to update Neo4j data on the regular basis. Neo4j has two types of nodes: 1.X and 2.Y . Below query and indexing, used to model the data:
CREATE INDEX ON :X(X_Number, X_Description,X_Type)
CREATE INDEX ON :Y(Y_Number, Y_Name)
using periodic commit
LOAD CSV WITH HEADERS FROM "file:///CR_n_Feature_new.csv" AS line
Merge(x:X{
X_Number : line.X_num,
X_Description: line.X_txt,
X_Type : line.X_Type,
})
Merge(y:Y{
Y_Number : line.Y_number,
Y_Name: line.Y_name,
})
Merge (y)-[:delivered_by]->(x)
Now there are two kinds of updates:
So I don't want to create a new node for the X_Number:1 node but just want to update the existing node properties like X_Description and X_Type.
Upvotes: 2
Views: 620
Reputation: 11216
You could just re-write your query to support new nodes and changes to existing nodes by merging only on the X_Number
or Y_Number
attributes.
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///CR_n_Feature_new.csv" AS line
MERGE (x:X {X_Number: line.X_num})
SET X_Description = line.X_txt, X_Type = line.X_Type
MERGE (y:Y {Y_Number: line.Y_number})
SET Y_Name=line.Y_name
MERGE (y)-[:delivered_by]->(x)
This way the MERGE
statements will always match the existing X
and Y
nodes based on the X_Number
and Y_Number
attributes which presumably are immutable. Then the existing Description
, X_Type
and Y_Name
attributes will be updated with the newer values.
Upvotes: 1