Nodes with variable attributes, how to model, index and query?

情到浓时终转凉″ 提交于 2019-12-11 23:36:57

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/19463557/nodes-with-variable-attributes-how-to-model-index-and-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!