3

Recently I have been using Neo4j for a project for a course I'm following. I've figured out how to use APOC to export my database to .csv.

However, the exported .csv file does not include the relationship ID. I use the following call to export the database:

CALL apoc.export.csv.all("export.csv",{})

I can also use the following Cypher query to obtain the relationship ID's:

MATCH ()-[r]-() RETURN ID(r)

There exists an apoc.export.csv.query() but I cannot think of a query that contains the information that is contained in the apoc.export.csv.all call and also contains the relationship ID.

I could potentially request the ID's separately and put them into export.csv using a Python script, but I'm not sure whether the order of the relationships would be the same for the separate calls/queries.

Any help is greatly appreciated!

4

1 回答 1

1

我看不到通过更改配置来做到这一点的方法。但是,如果您真的想要带有关系 ID 的输出,您可以克隆 apoc repo 并对apoc/export/csv/CsvFormat.java. 这是一种将关系 ID 添加到输出的非常快速的方法。

您需要将 ID 添加到标题中。我在下面的行中附加, "_id:id"了...

List<String> relHeader = generateHeader(relPropTypes, config.useTypes(), "_start:id", "_end:id", "_type:label", "_id:id");

List<String> header = generateHeader(relPropTypes, config.useTypes(), "_start:id", "_end:id", "_type:label", "_id:id");

你需要改变几行writeRels(SubGraph graph, CSVWriter out, Reporter reporter, Map<String, Class> relPropTypes, int cols, int offset)

我加了...

row[offset+3]=String.valueOf(rel.getId());

并在以下行中将偏移量从 3 更改为 4

collectProps(relPropTypes.keySet(), rel, reporter, row, 4 + offset);

它产生了一个看起来像这样的结果......

"_id","_labels","name","_start","_end","_type","_id","a_lot"
"0",":Node","A",,,,,
"1",":Node","B",,,,,
"2",":Node","C",,,,,
,,,"0","1","REL","0",""
,,,"0","2","LIKES","1","true"

我使用 3.2 社区进行测试。我不知道这些更改可能会对apoc.export.*集合的整体功能产生什么影响,也可能不产生什么影响。

于 2017-05-26T15:05:14.703 回答