Neo4J从查询结果创建新数据库

发布于 2025-01-25 08:00:29 字数 1725 浏览 3 评论 0原文

Neo4J有没有办法创建一个新的数据库,该数据库被另一个数据库中的某些查询数据填充了吗?

例如,我有一个由以下节点组成的数据库:

可以通过以下语句创建上面的图表: (在此示例中,想象图是完整的数据库)

CREATE (n0:Node)
CREATE (n1:Node)
CREATE (n2:Node {capital_letter: "A"})
CREATE (n3:Node)
CREATE (n4:Node)
CREATE (n5:Node)
CREATE (n6:Node {capital_letter: "B"})
CREATE (n7:Node)
CREATE (n8:Node {capital_letter: "A"})
CREATE (n9:Node {capital_letter: "B"})
CREATE (n10:Node)
CREATE (n2)-[:TRANSACTIONS]->(n0)
CREATE (n2)-[:TRANSACTIONS]->(n1)
CREATE (n2)-[:TRANSACTIONS]->(n3)
CREATE (n3)-[:TRANSACTIONS]->(n6)
CREATE (n4)-[:TRANSACTIONS]->(n2)
CREATE (n4)-[:TRANSACTIONS]->(n7)
CREATE (n6)-[:TRANSACTIONS]->(n5)

我的问题

是否有任何方法可以查询这些节点的子图片,然后将它们放入一个新的持久数据库中?

我想像以下内容:

INSERT INTO NEW DATABASE "NEW DB"
MATCH (a {capital_letter: "A"})
OPTIONAL MATCH (a {capital_letter: "A"})-[t1]-(a_neighbours)
MATCH (b {capital_letter: "B"})
OPTIONAL MATCH (b {capital_letter: "B"})-[t2]-(b_neighbours)
RETURN a, b, t1, t2, a_neighbours, b_neighbours

当然上述语句不起作用,但是 neo4j是否有可能构造这样的数据库?

请注意,我的数据库由100mio+节点组成,因此只有一种可行的方法确实很有帮助。

**我的最后一个手段是只查询数据,将其导出到.csv,然后通过neo4j-admin工具构建一个新数据库 https://neo4j.com/docs/operations-manual/manual/current/current/current/tutorial/neo4j-admin-import/

我只想知道如果有另一种(也许更快)的方式。

Is there a way in Neo4j to create a new Database, that gets populated by some query data from another database?

For Example, I have a Database that consists of the following Nodes:
enter image description here

The Graph from above can be created via the following statement:
(In this example imagine the graph is the full database)

CREATE (n0:Node)
CREATE (n1:Node)
CREATE (n2:Node {capital_letter: "A"})
CREATE (n3:Node)
CREATE (n4:Node)
CREATE (n5:Node)
CREATE (n6:Node {capital_letter: "B"})
CREATE (n7:Node)
CREATE (n8:Node {capital_letter: "A"})
CREATE (n9:Node {capital_letter: "B"})
CREATE (n10:Node)
CREATE (n2)-[:TRANSACTIONS]->(n0)
CREATE (n2)-[:TRANSACTIONS]->(n1)
CREATE (n2)-[:TRANSACTIONS]->(n3)
CREATE (n3)-[:TRANSACTIONS]->(n6)
CREATE (n4)-[:TRANSACTIONS]->(n2)
CREATE (n4)-[:TRANSACTIONS]->(n7)
CREATE (n6)-[:TRANSACTIONS]->(n5)

MY QUESTION:

Is there is any way to query for a sub-graph of these nodes, to then put them into a new persistent database?

For example I would like to build a new Database, with all A and B nodes, aswell as all their neighbours and all the relationships between them.

I imagine something like the following:

INSERT INTO NEW DATABASE "NEW DB"
MATCH (a {capital_letter: "A"})
OPTIONAL MATCH (a {capital_letter: "A"})-[t1]-(a_neighbours)
MATCH (b {capital_letter: "B"})
OPTIONAL MATCH (b {capital_letter: "B"})-[t2]-(b_neighbours)
RETURN a, b, t1, t2, a_neighbours, b_neighbours

Of course the above statement does not work, but is there any possibility in Neo4J to construct a Database like so?

Please note, that my Database consists of 100Mio+ Nodes so only a feasable approach is really helpful.

**My last resort would be to just query the data, export it to .csv and then construct a new database via the neo4j-admin tool https://neo4j.com/docs/operations-manual/current/tutorial/neo4j-admin-import/

I just want to know if there is another (maybe quicker) way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我入戏太深 2025-02-01 08:00:30

在NEO4J世界中,DML和DDL语句并非彼此隔离。通过转储文件或CSV导出源数据并导入它是唯一的本机选项。
如果您要连接到neo4j 通过另一种编程语言源图并将结果写入目标图。

In the Neo4j world, DML and DDL statements are not isolated from each other. Exporting the source data either through a dump file or CSV and importing it is the only native option.
If you are connecting to Neo4j through another Programming Language, you could build logic there to read from the source Graph and write the results to the destination Graph.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文