creating multiple properties on a node using batch inserter

17 views
Skip to first unread message

John Fry

unread,
Jun 16, 2016, 3:18:02 PM6/16/16
to Neo4j
Hi All,

when using the batch inserter java code below the property "name" doesn't appear on the node when I check it via a Cypher query.
The property "aka" does however appear on the node. If i don't add the "aka" property then the "name" property appears.

I have been scratching me head on this for a while now - I can't seem to create both "name" and "aka" properties.

Thanks for any help, John,



inserter.createDeferredSchemaIndex(MyLabel.Person).on("name").create();


...........

Map<String, Object> propertyName = new HashMap<String, Object>();

propertyName.put("name", nd.name);


long nodeId = -1;   

nodeId = inserter.createNode(propertyName, MyLabel.Person);


String[] aka = new String[nd.akaNames.size()];

aka = nd.akaNames.toArray(aka);        

Map<String, Object> propertyAka = new HashMap<String, Object>();

propertyAka.put("aka", aka);

inserter.setNodeProperties(nodeId, propertyAka);

John Fry

unread,
Jun 16, 2016, 3:21:42 PM6/16/16
to Neo4j

here is what cypher returns

START a=node(4238335)

> return keys(a);

+---------+

| keys(a) |

+---------+

| ["aka"] |

+---------+

1 row

50 ms

Michael Hunger

unread,
Jun 16, 2016, 3:54:23 PM6/16/16
to ne...@googlegroups.com
setNodeProperties overrides all properties

so the map you use there has to contain all the properties you want to have on your node

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Fry

unread,
Jun 16, 2016, 4:03:39 PM6/16/16
to Neo4j
I see - thanks Michael.
According to the docs i should be able to do this a mix object that are strings or arrays of strings. Does this seem safe/reasonable?

String[] aka = new String[nd.akaNames.size()];

aka = nd.akaNames.toArray(aka);  

Map<String, Object> property = new HashMap<String, Object>();

property.put("name"nd.name);      

property.put("aka"aka);

long nodeId = -1;   

nodeId = inserter.createNode(property, MyLabel.Person);

Michael Hunger

unread,
Jun 16, 2016, 4:50:25 PM6/16/16
to ne...@googlegroups.com
Yes, that's totally doable

John Fry

unread,
Jun 16, 2016, 5:55:59 PM6/16/16
to Neo4j
Tested and working - thank you.


On Thursday, June 16, 2016 at 12:18:02 PM UTC-7, John Fry wrote:
Reply all
Reply to author
Forward
0 new messages