neo4j
公司数据导入:
load csv WITH HEADERS from "file:///dt_object_sjtb.csv" as line
create (:ObjectNode {objId:line.objId, name:line.name,localId:line.local_id,localName:line.local_name,groupCode:line.group_code, projectId:line.project_id,objType:line.obj_type,
classCode:line.class_code, grouping:toInteger(line.grouping),infos:line.infos,virtualCodes:line.virtual_codes,createApp:line.create_app,updateApp:line.update_app,creator:line.creator,creationTime:line.creation_time,modifier:line.modifier,modifiedTime:line.modified_time,valid:toInteger(line.valid)})
create constraint for(o:ObjectNode) require (o.objId,o.projectId,o.groupCode) is unique;
CREATE INDEX FOR (o:ObjectNode) ON(o.projectId,o.groupCode);
CREATE INDEX FOR (o:ObjectNode) ON(o.classCode,o.projectId,o.groupCode);
CREATE INDEX FOR (o:ObjectNode) ON(o.objId);
load csv WITH HEADERS FROM "file:///dt_relation_sjtb.csv" AS line
match (from:ObjectNode{objId:line.obj_from,groupCode:line.group_code,projectId:line.project_id}),(to:ObjectNode{objId:line.obj_to,groupCode:line.group_code,projectId:line.project_id})
merge (from)-[r:ObjectNodeRelation{groupCode:line.group_code,projectId:line.project_id,graphCode:line.graph_code,relCode:line.rel_code,rId:line.rId}]->(to)
load csv WITH HEADERS FROM "file:///dt_relation_1.csv" AS line
match (from:ObjectNode{objId:line.obj_from,groupCode:line.group_code,projectId:line.project_id}),(to:ObjectNode{objId:line.obj_to,groupCode:line.group_code,projectId:line.project_id})
merge (from)-[r:line.graph_code-line.rel_code{groupCode:line.group_code,projectId:line.project_id,graphCode:line.graph_code,relCode:line.rel_code,rId:line.rId}]->(to)
MATCH (n) where n.classCode="a" and id(n)<500000 detach delete n
关系索引后建,导入关系才快(最后建关系索引)
CREATE INDEX FOR ()-[r:ObjectNodeRelation]->() ON(r.relCode,r.graphCode,r.projectId,r.groupCode);
CREATE INDEX FOR ()-[r:ObjectNodeRelation]->() ON(r.projectId,r.groupCode);
//create constraint FOR ()-[r:ObjectNodeRelation]->() require (r.rId,r.projectId,r.groupCode) is unique;
//CREATE constraint on ()-[r:ObjectNodeRelation]-() ASSERT exists(r.rId,r.projectId,r.groupCode)
//Property existence constraint requires Neo4j Enterprise Edition
CREATE CONSTRAINT rId_index FOR ()-[r:ObjectNodeRelation]-() REQUIRE r.rId IS NOT NULL
drop constraint constraint_596248c4
drop index constraint_596248c4
1. ./bin/neo4j stop
2. 删除历史数据和文件。
rm -rf /data/databases/neo4j/*
rm -rf /data/transactions/neo4j/*
3. ./bin/neo4j-admin database import full --nodes import/dt_object_2.csv --relationships import/dt_relation_2.csv --multiline-fields=true
4. ./bin/neo4j start