具有可变属性的节点,如何建模,索引和查询? [英] Nodes with variable attributes, how to model, index and query?

查看:89
本文介绍了具有可变属性的节点,如何建模,索引和查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下设置:用户和事件节点,带有(用户)-[:发布]->(事件).每个用户和事件都具有多个属性.这些属性因用户而异(事件与事件之间)差异很大,因此很难为其创建索引,但是我需要通过这些属性快速查询用户和事件.

我需要执行的最简单的查询形式:查找所有具有属性{x:'a',...}的用户,这些用户发布了至少一个具有属性{y:'b',...}的事件,但是尚未发布任何具有属性{z:'c',...}

的事件

所以我的问题是:如何最好地对此查询的数据建模? (并且neo4j是否适合该用例?),并且在必须拥有动态节点属性的情况下,如何使其快速工作. neo4j中的AFAIK不能具有复合索引,我是否需要为用户/事件的每个属性创建索引?

任何帮助/想法都将受到欢迎.谢谢!

解决方案

对于用户,我猜最简单的方法是为可能用于查找用户的所有属性键配置自动索引. 为了将用户与事件相关联,我将在事件细节方面更加详细.例如.而不是一般的PUBLISH关系类型,请尝试使用例如

然后,您的查询将使用自动索引查找一个或多个用户,然后根据特定的关系类型与事件进行匹配.这样做会防止在遍历时检查性能,这对性能很有好处.

I have the following setup: user and event nodes, with (user)-[:PUBLISH]->(event). each user and event both have multiple properties. These properties vary significantly from user to user (and event to event) which makes it hard to create indexes for them, however I need to query both the users and event by these attributes in a fast manner.

The simplest form of query I need to perform: find all users with properties {x: 'a', ...} that have published at least one event with properties { y: 'b', ...} but haven't published any event with properties {z: 'c', ...}

So my questions are: how can I best model the data for this query? (and is neo4j suitable for this use case, for that matter?) and how do I make it work fast given that I MUST HAVE dynamic node attributes. AFAIK in neo4j one cannot have compound indexes, do I need to create an index for each property of user/event?

Any help/ideas will be most welcome. Thank you!

解决方案

For users I guess the simplest approach would be to configure autoindexing for all property keys that are potentially used for looking up users. To associate users to events, I'd try to be more verbose on event specifics. E.g. instead of a generic PUBLISH relationship type, try to use e.g. PUBLISH_EVENT_TYPEA, PUBLISH_EVENT_TYPEB, PUBLISH_EVENT_TYPEC ....

YOur query would then look up one or more users using the autoindex and then match to the event based on the specific relationship types. Doing so prevents inspection of properties while traversing which is good for performance.

这篇关于具有可变属性的节点,如何建模,索引和查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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