Mik378
Mik378

Reputation: 22181

Neo4j / Good way to retrieve nodes created from a specific startDate

Let's suppose this Cypher query (Neo4j):

MATCH(m:Meeting)
WHERE m.startDate > 1405591031731
RETURN m.name

In case of millions Meeting nodes in the graph, which strategy should I choose to make this kind of query fast?

I haven't use cases when I would query a range: FROM this startDate TO this endDate.

By the way, it seems that simple indexes work only when dealing with equality... (not comparison like >).

Any advice?

Upvotes: 0

Views: 763

Answers (1)

Kenny Bastani
Kenny Bastani

Reputation: 3308

Take a look at this answer: How to filter edges by time stamp in neo4j?

When selecting nodes using relational operators, it is best to select on an intermediate node that is used to group your meeting nodes into a discrete interval of time. When adding meetings to the database you would determine which interval each timestamp occurred within and get or create the intermediate node that represents that interval.

You could run the following query from the Neo4j shell on your millions of meeting nodes which would group together meetings into an interval of 10 seconds. Assuming your timestamp is milliseconds.

MATCH (meeting:Meeting)
MERGE (interval:Interval { timestamp: toInt(meeting.timestamp / 10000) }
MERGE (meeting)-[:ON]->(interval);

Then for your queries you could do:

MATCH (interval:Interval) WHERE interval.timestamp > 1405591031731
WITH interval
MATCH (interval)<-[:ON]-(meeting:Meeting)
RETURN meeting

Upvotes: 1

Related Questions