Skip to content

Commit aac4980

Browse files
authored
Document update/change/delete in block format incremental import (#2177)
1 parent 4f1f932 commit aac4980

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

@@ -1423,6 +1426,124 @@ neo4j_home$ --nodes persons.csv --nodes games.csv --id-type string
14231426
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.
14241427
====
14251428

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

14271548
== Importing data that spans multiple lines
14281549

0 commit comments

Comments
 (0)