3

I need your advice on neo4j export things…. I used ” apoc.export.cypher.query” to export my nodes and relationships to csv files , however the exported contents are cypher statements. This is a sample exported csv file :

begin
CREATE (:`ITEM`:`UNIQUE IMPORT LABEL` {`product_number`:5305, `bi_key`:1910, `mean_review_score`:“4.42”, `review_count`:“24", `site_availability_bitmask`:“2129759”, `UNIQUE IMPORT ID`:117});
CREATE (:`ITEM`:`UNIQUE IMPORT LABEL` {`product_number`:7123, `bi_key`:2261, `UNIQUE IMPORT ID`:121});
CREATE (:`ITEM`:`UNIQUE IMPORT LABEL` {`product_number`:7436, `bi_key`:2330, `mean_review_score`:“4.41", `review_count`:“117”, `site_availability_bitmask`:“2113295", `UNIQUE IMPORT ID`:125});
CREATE (:`ITEM`:`UNIQUE IMPORT LABEL` {`product_number`:7697, `bi_key`:2382, `UNIQUE IMPORT ID`:130});
CREATE (:`ITEM`:`UNIQUE IMPORT LABEL` {`product_number`:7743, `bi_key`:2388, `mean_review_score`:“4.33”, `review_count`:“18", `site_availability_bitmask`:“2113295”, `UNIQUE IMPORT ID`:133});
commit
begin
CREATE INDEX ON :`ITEM`(`product_number`);
CREATE CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT node.`UNIQUE IMPORT ID` IS UNIQUE;
commit
schema await
begin
MATCH (n:`UNIQUE IMPORT LABEL`)  WITH n LIMIT 10 REMOVE n:`UNIQUE IMPORT LABEL` REMOVE n.`UNIQUE IMPORT ID`;
commit
begin
DROP CONSTRAINT ON (node:`UNIQUE IMPORT LABEL`) ASSERT node.`UNIQUE IMPORT ID` IS UNIQUE;
commit

But this is not what I want , is there anyway to export graph content directly to csv files with csv formats? Or I should rely on parsing the file above ... or using neo4j jdbc driver to execute cypher and write the result in csv ? I need to do this pragmatically … I mean it is a web application from which users should be able to extract graph content to csv formats

Lina
  • 1,217
  • 1
  • 15
  • 28

2 Answers2

13

Instead of using apoc.export.cypher.query you can use apoc.export.csv.query to write the results to a CSV file. For example:

CALL apoc.export.csv.query("MATCH (u:User)-[r:RATED]->(m:Movie) RETURN u.name, r.rating, m.title LIMIT 10", "results.csv", {})

More info in the docs here

William Lyon
  • 8,371
  • 1
  • 17
  • 22
0

the method apoc.export.csv() seems super slow.

I'm running a VM with neo4j. My procedure is to have a dictionary of cypher queries to be executed through a python script running in the background... All good.

The last step of the python script to execute the exportation query, for a node with 27M unique records and all their properties (maybe 10 columns). this is the cypher query:

with collect(distinct r) as my_stuff
call apoc.export.csv.data(my_stuff, [], 'neo4j_output.csv', {})
    yield file, source, format, nodes, properties, time, rows, batchSize, batches, done, data
    return file, source, format, nodes, properties, time, rows, batchSize, batches, done, data, size(researcher)

It lasted 40 mins to populate the database from a GCP bucket... But it's lasting way more in exporting the data to the default path /var/lib/neo4j/import/.

Any insights of how speeding things up are welcome

albertovpd
  • 115
  • 2
  • 10