Use CSV to populate Neo4j

I am very new to Neo4j. I participate in this graph database. I need to upload a csv file to the Neo4j database. I try from 2 days, I could not find good information on reading a csv file in Neo4j. Please suggest me use example code or blogs to read the csv file in Neo4j.

Example: Suppose if I have a csv file. So how can we read it in Neo4j

id name language 1 Victor Richards West Frisian 2 Virginia Shaw Korean 3 Lois Simpson Belarusian 4 Randy Bishop Hiri Motu 5 Lori Mendoza Tok Pisin 
+4
source share
5 answers

You can try https://github.com/sroycode/neo4j-import

This fills the data directly from a pair of CSV files (records should be split into COMMA)

To build: (you need maven)

 sh build.sh 

The node file has a required field identifier and any other fields that you like

 NODES.txt id,name,language 1,Victor Richards,West Frisian 2,Virginia Shaw,Korean 3,Lois Simpson,Belarusian 

The relationship file has 3 required fields from, to, type. Assuming you have a field age (long integer) and information, the relationship file will look like

 RELNS.txt from,to,type, age@long ,info 1,2,KNOWS,10,known each other from school 1,3,CLUBMATES,5,member of country club 

Duration:

 sh run.sh graph.db NODES.txt RELNS.txt 

will create graph.db in the current folder, which you can copy to the neo4j data folder.

Note: If you use neo4j later than 1.6. *, Add this line to conf / neo4j.properties

 allow_store_upgrade = true 

Good luck.

+4
source

Please take a look at https://github.com/jexp/batch-import

Can be used as a starting point.

+3
source

There is nothing available for the general loading of CSV data into Neo4j, because the source and target data structures are different: CSV data is tabular, while Neo4j contains graph data.

To achieve this import, you will need to add a separate step to translate your tabular data into some form of graph (like a tree) before it can be loaded into Neo4j. Further, using the tree structure, the page below shows how the XML data can be converted to Cypher, which can then be directly executed against the Neo4j instance.

http://geoff.nigelsmall.net/xml2graph/

Please feel free to use this tool if it helps (remember that it can only work with small files), but this, of course, will require converting CSV to XML first.

Greetings

Nigel

+2
source

There is probably no known CSV importer for neo4j, you must import it yourself:

I usually do this myself through gremlin g.loadGraphML (); function. http://docs.neo4j.org/chunked/snapshot/gremlin-plugin.html#rest-api-load-a-sample-graph

i parse my data with some external script in xml syntax and load a specific xml file. you can see the syntax here: https://raw.github.com/tinkerpop/gremlin/master/data/graph-example-1.xml it takes a few minutes to parse a 100 megabyte file.

in your case, what you need to do is a simple two-sided graph with vertices consisting of users and languages, as well as the edge “says”. if you know some kind of programming, create user nodes with parameters id , name | unique language nodes with name | where you need to connect each user to a specific language. note that users may be duplicated, but languages ​​may not.

+1
source

I think your question is too general. What does your csv file contain? The logical meaning of the contents of the csv file can vary greatly. An example of two columns with identifiers that will represent entities related to each other.

  3921 584
 831 9891
 3841 92
 ...

In this case, you can either write a piece of BatchInserter code that will import it faster, see http://docs.neo4j.org/chunked/milestone/batchinsert.html .

Or you can import using a regular GraphDatabaseService with a transaction size of several thousand inserts for performance. See how to set up and use the db graph at http://docs.neo4j.org/chunked/milestone/tutorials-java-embedded.html .

0
source

Source: https://habr.com/ru/post/1441986/


All Articles