在 Neo4J 中存储多个图形 [英] Storing multiple graphs in Neo4J

查看:44
本文介绍了在 Neo4J 中存储多个图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个将关系信息存储在 MySQL 表中的应用程序(contact_id、other_contact_id、strength、recorded_at).如果我需要做的只是显示联系人的关系,或者甚至生成两个联系人的相互联系人列表,那就没问题了.

I have an application that stores relationship information in a MySQL table (contact_id, other_contact_id, strength, recorded_at). This is fine if all I need to do is show who a contact's relationships are or even to generate a list of mutual contacts for two contacts.

但现在我需要生成这样的统计数据:2011 年 1 月强度为 3 或更高的双向连接总数是多少"或(假设每个联系人都是一个组的一部分)哪个组拥有最多与其他组等的连接数.

But now I need to generate stats like: 'what was the total number of 2-way connections of strength 3 or better in January 2011' or (assuming that each contact is part of a group) 'which group has the most number of connections to other groups' etc.

我很快发现生成这些统计数据的 SQL 变得非常笨拙.

I quickly found that the SQL for generating these stats became unwieldy real fast.

所以我写了一个脚本,对于任何给定的日期,它都会在内存中生成一个图表.然后我可以针对该图表运行任何我想要的统计数据.更容易理解,总的来说,性能也更高——除了生成图形部分.

So I wrote a script that for any given date it will generate a graph in memory. I could then run whatever stat I wanted against that graph. Much easier to understand and in general, much more performant also -- except for the generating the graph part.

我的下一个想法是缓存这些图,这样我就可以在需要运行新统计数据时调用它们(或生成稍后的图:例如,对于今天的图,我采用昨天的图并应用自昨天以来发生的任何更改).我尝试了 memcached,它运行良好,直到图表增长 > 1 MB.

My next thought was to cache those graphs so I could call on them whenever I needed to run a new stat (or generate a later graph: eg for today's graph I take yesterday's graph and apply any changes that happened since yesterday). I tried memcached which worked great until the graphs grew > 1 MB.

所以现在我正在考虑使用像 Neo4J 这样的图形数据库.

So now I'm thinking about using a graph database like Neo4J.

唯一的问题是,我没有只有一张图表.或者我这样做,但它会随着时间的推移而变化,我需要能够使用不同的参考时间来查询它.

Only problem is, I don't have just one graph. Or I do, but it is one that changes over time and I need to be able to query it with different reference times.

那么,我可以:

  • 在 Neo4J 中存储多个图形并分别重新检索/交互?然后我会为每个日期创建和存储单独的社交图.

  • 向每条边添加有效的时间戳和来自时间戳并适当过滤图形:因此,如果我想要5 月 1 日"的图形,我将只遵循在5 月 1 日"之前创建的两个 noeds 之间的最新边(如果所有边都是在 5 月 1 日之后创建的,那么这些节点将不会连接).

我对图形数据库很陌生,所以任何帮助/指针/提示将不胜感激.

I'm pretty new to graph databases so any help/pointers/hints will be appreciated.

推荐答案

现在你只能在一个 Neo4j 实例中存储一个图形数据库,但是这个图形数据库可以包含任意多个不同的子图形.您只需在执行全局操作(如索引查询)时记住这一点,但在那里您可以执行包含时间戳属性的复合查询,以限制结果.

Right now you can store just one graph database in a single Neo4j instance, but this one graphdb can contain as many different sub-graphs as you like. You only have to keep that in mind when doing global operations (like index queries) but there you can do compound queries that include timestamped properties as well to limit the results.

这样做的一种方法是,正如您所说,向边添加时间信息以表示给定日期的图形结构,然后您可以遍历当时的图形结构.

One way of doing that is, as you said adding temporal information to edges to represent the structure of a graph for a given date you can then traverse the structure of the graph back then.

参考节点在 Neo4j 中有不同的含义.

Reference node has a different meaning in Neo4j.

每天使用类别节点(并链接它们并聚合它们以获得更高级别的时间跨度)是对节点进行分类而不是索引属性的更图形化的方式.(实际上,这些是图内索引,您可以轻松地将它们包含在您的遍历和图查询中).

Using category nodes per day (and linking them and also aggregating them for higher level timespans) is the more graphy way of categorizing nodes than indexed properties. (Effectively these are in-graph indices that you can easily include in your traversals and graph queries).

只要您只对不同的时间结构感兴趣,就不必复制节点.如果您的节点也不同(例如更改属性,您可以复制它们,从而有效地创建不同的子图)或在每个节点上创建一个连接的历史节点列表,其中仅包含更改(或完整快照,取决于您的要求).

You don't have to duplicate the nodes as long as you are only interested in different temporal structures. If your nodes are also different (e.g. changing properties, you could either duplicate them, and so effectively creating different subgraphs) or create a connected list of history nodes on each node that contain just the changes (or the full snapshot depending on your requirements).

您的域听起来非常适合图形数据库.如果您有更多更详细的问题,请随时加入 Neo4j 邮件列表.

Your domain sounds very fitting for the graph database. If you have more and detailed questions feel free to join the Neo4j mailing list.

这篇关于在 Neo4J 中存储多个图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆