在Neo4j中存储文本 [英] Storing text in Neo4j

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

问题描述

我们正在使用Neo4J并喜欢它.我们在其中进行各种图形处理.但是,我们做的某些事情不是图形.例如,我们保留对特定类型节点的所有更改的日志:

We're using Neo4J and liking it. We do all sorts of graphy things in it. However, some of what we do is not graphy. For example, we keep a log of all changes to a certain type of node:

(n)-[:CHANGE]->(c1)-[:CHANGE]->(c2) etc etc

此更改列表的长度可以达到20或30个c1节点.虽然看起来很怪异,但我并没有真正的问题. (当然,我现在变得更聪明了,并且由于每个:CHANGE关系中都有一个日期,因此我可以从n开始就对所有c1节点进行豪顿.)

This list of changes can get to be 20 or 30 c1 nodes long. While it looks weird, I don't have a real problem with it. (Of course, I am smarter now, and since each :CHANGE relationship has a date in it, I could porcupine all the c1 nodes right from n. But whatever.)

但是,如果我想存储大量文本或图像怎么办?在节点中存储大量数据是否有问题?我可以为这些事情使用不同的数据库,但这只会增加经营业务所需的技能.当然,在两个不同的数据库中合并数据始终是PITA.

But what if I wanted to store large amounts of text, or images. Is there a problem with storing large amounts of data in a node? I could use a different database for these things, but this just increases the skill set required to run the business. And of course, joining data in two disparate databases is always a PITA.

因此,我需要担心在单个属性中存储大量文本吗?我是否需要避免像上面那样创建日志?

So I need to worry about storing large amounts of text in a single property? Do I need to avoid creating logs in the way I did above?

推荐答案

创建事件的链接列表,无论它们是什么,都可以.甚至会说它是石墨的!在 ChangeFeed 的情况下,我们经常使用这种方法进行类似的操作.

Creating linked lists of events, whatever they may be, is fine. It'd even say it is graphy! We use this approach a lot, in the case of ChangeFeed for something similar to what you're doing.

在Neo4j中,这样的链接列表实际上比豪猪"要好,因为如果要查找所有更改,则无论如何都要遍历所有关系.但是在链表的情况下,您不必查看属性即可对其进行排序.实际上,最好的方法是混合方法,例如 TimeTree .

In Neo4j, such a linked list is actually better than a "porcupine", because you have to traverse all the relationships anyway, if you're looking for all changes. But in the linked list case, you don't have to look at properties to order them. In fact, the best approach is a hybrid approach, like the TimeTree.

对于存储大量文本或图像,Neo4j并不是最佳选择.最好使用另一个数据库,尤其是如果这些数据库的数量很大(>数十万)时.

As for storing large amounts of text or images, Neo4j is not the best place for it. Another database would be best, especially if the volume of these is large ( > hundreds of thousands).

但是,如果您确实希望将它们存储在Neo4j中,则要记住的一件事是,一旦访问单个属性,Neo4j将加载节点/关系的所有属性.因此,为了即使在Neo4j中使用文本/图像也能获得良好的性能,我将它们存储在它们自己的节点中.这样,只有在确实需要它们时才可以加载它们,而在常规遍历期间则不能加载它们.

But if you do want to store them in Neo4j, one thing to keep in mind is that Neo4j will load all the properties of a node/relationship once a single property is accessed. So in order to achieve good performance even with text/images in Neo4j, I would store them in a node of their own. That way, you can only load them if you really need them, but not during regular traversals.

例如:

CREATE (b:BlogPost {title:'Neo4j Rocks', author:'Tony Ennis', date:".."})-[:HAS_BODY]->(:BlogPostBody {content:'..'})

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

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