Neo4j - convert node attribute storage from string

2019-08-06 15:04发布

问题:

I have a Neo4j database that was initially created from a Perl script using the Rest::Neo4p Perl module. For some unknown reason, one of the attributes on the nodes was created as a string, even though the values for said attribute on all of the nodes are numeric (verified through a Cypher regex search of that attribute).

Is there an easy way to convert the attribute's storage type from string to a number short of recreating the database? Perhaps a Cypher query that would create a new attribute of numeric type using the value from the textual attribute?

Thanks,

Chris

回答1:

I am not sure how (and if) you can do that with Cypher, but you could convert the attributes using Gremlin:

g.V.sideEffect { it.my_property_name = Integer.parseInt(it.my_property_name) }.iterate()

You can also use a Java extension or just load the DB in embedded mode and convert using Java traversals.



标签: neo4j cypher