Skip to content

Commit af8e635

Browse files
authored
Document update/change/delete in block format incremental import (#2177) (#2182)
Cherry-picked from #2177
1 parent 3e34283 commit af8e635

File tree

1 file changed

+126
-5
lines changed

1 file changed

+126
-5
lines changed

modules/ROOT/pages/tools/neo4j-admin/neo4j-admin-import.adoc

Lines changed: 126 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -607,12 +607,15 @@ For more information, see <<import-tool-header-format>>.
607607
====
608608
* New relationships between existing or new nodes.
609609

610-
The incremental import command cannot be used to:
610+
Starting from 2025.01, the incremental import command can also be used for:
611611

612-
* Add new properties to existing nodes or relationships.
613-
* Update or delete properties in nodes or relationships.
614-
* Update or delete labels in nodes.
615-
* Delete existing nodes and relationships.
612+
* Adding new properties to existing nodes or relationships.
613+
* Updating or deleting properties in nodes or relationships.
614+
* Updating or deleting labels in nodes.
615+
* Deleting existing nodes and relationships.
616+
617+
This is supported only by `block` format.
618+
See <<#_applying_changes_to_data_via_csv_files>> for more information.
616619

617620
=== Parameters
618621

@@ -1409,6 +1412,124 @@ neo4j_home$ --nodes persons.csv --nodes games.csv --id-type string
14091412
The `id` property of the nodes in the `persons` group will be stored as `long` type, while the `id` property of the nodes in the `games` group will be stored as `string` type, as the global `id-type` is a string.
14101413
====
14111414

1415+
[role=label--new-2025.01.0]
1416+
== Applying changes to data via CSV files
1417+
1418+
You can use CSV files to update existing nodes, relationships, labels, or properties during incremental import.
1419+
1420+
[NOTE]
1421+
====
1422+
This feature is supported only by `block` format.
1423+
====
1424+
1425+
=== Set an explicit action for each row
1426+
1427+
You can set an explicit action for each row in the CSV file by using the `:ACTION` keyword in the header file.
1428+
If no action is specified, the import tool works as in full import mode, creating new data.
1429+
1430+
The following actions are supported:
1431+
1432+
* `empty` = `CREATE` (default)
1433+
* `C`, `CREATE` - Creates new nodes and relationships, with or without properties, as well as labels.
1434+
* `U`, `UPDATE` - Updates existing nodes, relationships, labels, and properties.
1435+
* `D`, `DELETE` - Deletes existing nodes or relationships.
1436+
Deleting a node also deletes its relationships (`DETACH DELETE`).
1437+
1438+
1439+
.Using actions in CSV files to update nodes
1440+
[source, cypher, role="nocopy"]
1441+
----
1442+
:ACTION,uid:ID(label:Person),name,:LABEL
1443+
CREATE,person1,"Keanu Reeves",Actor
1444+
UPDATE,person2,"Laurence Fishburne",Actor
1445+
DELETE,person4,,
1446+
----
1447+
1448+
Nodes are identified by their unique property value for the key/label combination that the header specifies.
1449+
1450+
.Using actions in CSV files to update relationships
1451+
[source, cypher, role="nocopy"]
1452+
----
1453+
:ACTION,:START_ID,:END_ID,:TYPE,role
1454+
CREATE,person1,movie1,ACTED_IN,"Neo"
1455+
UPDATE,person2,movie1,ACTED_IN,"Morpheus"
1456+
DELETE,person3,movie1,ACTED_IN
1457+
----
1458+
1459+
Relationships are identified non-uniquely by their start and end node IDs, and their type.
1460+
1461+
To further narrow down selection you can tag a property column as an identifier to help out in selecting relationships uniquely (or at least more uniquely).
1462+
1463+
.Using actions in CSV files to update relationships with identifier properties
1464+
[source, cypher, role="nocopy"]
1465+
----
1466+
:ACTION,:START_ID,:TYPE,:END_ID,p1{identifier:true},name,p4
1467+
U,person1,KNOWS,person2,abc,"Keanu Reeves","Hello Morpheus"
1468+
U,person2,KNOWS,person1,def,"Laurence Fishburne","Hello Neo"
1469+
----
1470+
1471+
The data in the `p1` column for these relationships helps select relationships "more uniquely" if a multiple of `1,KNOWS,2` exists.
1472+
There can also be multiple identifier properties defined in the header.
1473+
Identifier properties match the selected relationships and will not be set on the relationships that already have them.
1474+
1475+
=== Update existing labels
1476+
1477+
You can add or remove one or more labels from an existing node by prepending the clause `LABEL` in the header with a `+` (default) or `-`:
1478+
1479+
* `:+LABEL` - Add one or more labels to an existing node.
1480+
* `:-LABEL` - Remove one or more labels (if they exist) from an existing node.
1481+
1482+
1483+
For example, a file could have the following format:
1484+
1485+
[source, csv]
1486+
----
1487+
uid:ID(label:Person),:+LABEL,:-LABEL,name,age
1488+
person1,Actor,Producer,"Keanu Reeves",55
1489+
person2,Actor;Director,,"Laurence Fishburne",60
1490+
----
1491+
1492+
In this case, all labels in the second column are added and all the labels in the third column are removed (if they exist).
1493+
1494+
=== Remove existing properties
1495+
1496+
You can remove properties from existing nodes or relationships by a `:-PROPERTY` column in the header.
1497+
In the contents of this field you can add zero or more property names to remove from the entity.
1498+
For example:
1499+
1500+
.Remove nodes' properties
1501+
[source, cypher, role="nocopy"]
1502+
----
1503+
:ACTION,uid:ID(label:Person),:-PROPERTY
1504+
U,person1,age;hometown
1505+
----
1506+
1507+
Properties `age` and `hometown` are removed from the node with the `uid:ID` `person1`.
1508+
1509+
.Remove relationships' properties
1510+
[source, cypher, role="nocopy"]
1511+
----
1512+
:ACTION,:START_ID,:END_ID,:TYPE,:-PROPERTY
1513+
U,person1,movie1,ACTED_IN,role;description
1514+
----
1515+
1516+
Properties `role` and `description` are removed from the relationship with the `:START_ID` `person1`, `:END_ID` `movie1`, and `:TYPE` `ACTED_IN`.
1517+
1518+
.Using actions in CSV files to update labels and properties
1519+
[source, cypher, role="nocopy"]
1520+
----
1521+
:ACTION,uid:ID(label:Person),:LABEL,:-LABEL,:-PROPERTY,name,height:int
1522+
U,person1,Actor,Producer,age;hometown,Henry",185
1523+
----
1524+
1525+
One CSV entry can specify all types of updates to one entity at the same time.
1526+
In this example, the node `person1` is updated with:
1527+
1528+
* added `Actor` label
1529+
* removed `Producer` label
1530+
* removed `age` and `hometown` properties
1531+
* set `name="Henry"` property
1532+
* set `height=185` property
14121533

14131534
== Importing data that spans multiple lines
14141535

0 commit comments

Comments
 (0)