Graph data comes in different formats, and sometimes it's a combination of two or more formats. It is very important to learn about the various ways to import data, which is in different formats into Neo4j. In this recipe, you will learn how to import data present in the CSV file format into the Neo4j graph database server. A sample CSV file is shown as follows:
Getting ready
To get started with this recipe, install Neo4j by using the steps from the earlier recipes of this chapter.
How to do it...
There are several methods that you can use to import data which is in the CSV format or Excel into Neo4j, which are described in the sections that follow.
Using a batch importer
There is excellent tool written by Michael Hunger, which can be cloned from https://github.com/jexp/batch-import.
The CSV file has to be converted into the format specified in the readme file. The tool is very flexible in terms of the number of properties and the types of each property. The nodes and relationships can be within the same file or within multiple files. The example file format is present in the sample directory. To run the tool, use the following command:$ wget https://dl.dropboxusercontent.com/u/14493611/batch_importer_22.zip$ unzip batch_importer_22.zip# Download sample nodes.csv and rels.csv from the github repo under sample$ import.sh test.db nodes.csv rels.csv$ cp test.db ${NEO4J_ROOT}/data/graph.db复制代码
Each parameter in the command has been fully explained in the readme file.
Note
The batch import tool also supports a parallel batch inserter, which can speed up the process of importing data from a large number of nodes and relationships.
Benchmark figures claimed by the batch importer tool are 2 billion nodes and 20 billion relationships in 11 hours (500K elements/second).
This is claimed over the EC2 high I/O instance.