Neo4j cypher time interval histogram query of time tree

孤人 提交于 2020-01-02 09:01:05

问题


I would like to build an histogram on time series stored as time tree in neo4j. The data structures are event done by a user each has timestamp, say user purchases category. What I need to have is the number of browsing on each category by each user between start and end time, with interval of (1 second to days) My model feats graph db very nicely, as I read neo4j documentation I could not find any way to do it in one query, and I'm afraid that calling for each user would be very slow.

I am aware to cypher capabilities, but I have no idea how to create such query. I am looking for something like this (not working)

MATCH startPath=(root)-[:`2010`]->()-[:`12`]->()-[:`31`]->(startLeaf),
endPath=(root)-[:`2011`]->()-[:`01`]->()-[:`03`]->(endLeaf),
valuePath=(startLeaf)-[:NEXT*0..]->(middle)-[:NEXT*0..]->(endLeaf),
vals=(middle)-[:VALUE]->(event)
WHERE root.name = 'Root'
RETURN event.name, count(*)
ORDER BY event.name ASC
GROUP BY event.timestamp % 1000*60*10 // 10 minutes histogram bar 

Then I'd like to have a report, for how many users browse to each site category:

0-9 news 5, commerce 3 ; 10-19 news 6, commerce 19; 1 20-29 news 2, commerce 8;

Any idea if it is optional with neo4j time tree model? if so how? :-)


回答1:


Does this work?

MATCH
  startPath=(root)-[:`2010`]->()-[:`12`]->()-[:`31`]->(startLeaf),
  endPath=(root)-[:`2011`]->()-[:`01`]->()-[:`03`]->(endLeaf),
  valuePath=(startLeaf)-[:NEXT*0..]->(middle)-[:NEXT*0..]->(endLeaf),
  vals=(middle)-[:VALUE]->(event)
WHERE root.name = 'Root'
RETURN event.name, event.timestamp % 1000*60*10 AS slice, count(*)
ORDER BY slice ASC

Basically I just added the event.timestamp % 1000*60*10 into the return so that Neo4j will use that as a grouping criteria



来源:https://stackoverflow.com/questions/31785783/neo4j-cypher-time-interval-histogram-query-of-time-tree

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