简体   繁体   English

Neo4J 2.0如何重构数据库以引入Date节点

[英]Neo4J 2.0 How to refactor the database to introduce Date nodes

I have existing database which i just imported from SQL DB, for eg lets call it Order which has property called PlacedOn of type DateTime stored as part of the node which looks like 2013-05-01T02:15:18+00:00 . 我有现成的,我刚刚从SQL数据库导入的数据库,用于如让叫它Order已性质称为PlacedOn类型的DateTime存储为看起来像节点的一部分2013-05-01T02:15:18+00:00

I am now looking to extract the date time and create an association such that I am able query for all the Orders for a month or a year easily. 我现在正在寻找提取日期时间并创建一个关联,以便能够轻松查询一个月或一年的所有Orders

Basically what I want to achieve is make the association look as below: 基本上我要实现的是使关联如下所示:

(o:Order)-[:PLACED_ON]->(d:Day)-[:BELONGS_TO]->(m:Month)-[:BELONGS_TO]->(y:Year)

For a performance test I have created 1100000 nodes , so having to load it in my c# code and creating it is not practical, so is there a way in Cypher or any other way in Webadmin that can allow me to extract the day month and year part and create the nodes with the associations as mentioned above. 对于性能测试,我已经创建了1100000 nodes ,因此必须将其加载到我的C#代码中并创建它是不实际的,因此Cypher或Webadmin中的任何其他方式都可以让我提取月份和年份分离并创建具有上述关联的节点。

Regards Kiran 问候基兰

Please take a look at this Cypher query for creating a DateTime tree in Neo4j 2.0: 请查看此Cypher查询,以在Neo4j 2.0中创建DateTime树:

https://gist.github.com/kbastani/8519557#file-calendaryear-cql https://gist.github.com/kbastani/8519557#file-calendaryear-cql

Run the CalendarYear Cypher script for each year of data. 为每年的数据运行CalendarYear Cypher脚本。

You'll need to parse your DateTime timestamp value to extract the Year, Month, Day integer values. 您需要解析DateTime时间戳值以提取Year,Month和Day整数值。 Then for each of your orders you'll need to attach a day node. 然后,对于每个订单,您都需要附加一个日节点。 What I suggest is that when you import your data, you add in properties to your order which have the Year, Month, Day values. 我的建议是,当您导入数据时,需要在订单中添加具有Year,Month,Day值的属性。

Then run a Cypher statement in batches to add in your timeline, by each month of a year with records: 然后分批运行一个Cypher语句以添加到您的时间轴中,按每年的每个月添加记录:

MATCH (order:Order { month: 5, year: 2014 })
WITH collect(order) as orders
FOREACH (order in orders |
    MERGE (day:Day { day: order.day, month: order.month, year: order.year })
    CREATE (day)<-[:PLACED_ON]-(order))

Now you can query your data using the timeline index. 现在,您可以使用时间轴索引查询数据。

MATCH (order:Order)-[:PLACED_ON]->(day:Day { day: 1, month: 5, year: 2013 })
RETURN order

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM