0

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!

alexandru.topliceanu
  • 2,364
  • 2
  • 27
  • 38

1 Answers1

2

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.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97
  • It works! I created indexes for both users and events. I used PUBLISH_EVENT_TYPE instead of PUBLISH like you suggested and I indexed the relationships. How can I do a cypher query to get all users that didn't publish a certain type of event? – alexandru.topliceanu Oct 19 '13 at 12:56