cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Cypher Querying/Modeling Help/Guidance needed. (Multiple Relationships OR List Property)

Hi,

Got unique model for which I am looking for help find the query solution.

Model:
Two nodes (A,B) are connected by relationship say, R. This R has two list properties - updates/states.

              (A)-[r:R {updates, states}]->(B)
  • Updates hold Dates and States hold String - ACTIVE/REMOVED etc.
  • Dates in updates are ascending.
  • For each Date, we have corresponding State, Length of both the properties will be same.

Query:
We need to find all A, B, where a given Date(d) is provided as parameter. We need to find the dates in updates property, find the index of date == (d), then find the corresponding states[index], if this is ACTIVE - return the result, else ignore.

Does it make sense to use CYPHER or try with UDFs for this use case?

Also, will it make sense to model the problem differently? Instead of storing the updates/states as list, we can always create a new relationship with different property - update/state. Would that be more helpful? We have to store at least 30 days of data, hence between two nodes, approx 30 relationships will be present (if we pick this approach).

Volume: For single date, we have approx 200K nodes and 1.3 M relationships

Please put in your two cents. Much appreciated.

1 REPLY 1

This is a case where you find that the concept of this date and state pairing is an important entity in your graph, which usually means you should model it as a node instead of a relationship, one node per date and state.

This would allow you to add an index on the updated property for nodes using the new label. And you can make this more performant by using an additional :Active label (or :ActiveSomething, basically appending active as a type of whatever the node type is supposed to be) for the nodes that are active for that date, allowing you to index that and do quick lookups by date alone which will fail fast if there was no node of that type that was active for the date in question:

MATCH (A)-->(r:ActiveR)-->(B)
WHERE r.updated = $updateDate
RETURN A, B

This supposes only one incoming and one outgoing relationship for A and B. Otherwise you may want to use specific relationship types to those nodes in your pattern.