zoukankan      html  css  js  c++  java
  • NEO4J 图数据库使用APOC数据导入

                                                                     Neo4j 数据导入

    一、安装与部署

                   直接在官网下载安装包安装,解压即可。

    二、下载相应的jar包

    apoc 包下载链接: https://github.com/neo4j-contrib/neo4j-apoc-procedures/releases

    1.sqlserver 数据导入neo4j的jar包

    apoc-3.4.0.1-all.jar     mssql-jdbc-6.2.2.jre8.jar     sqljdbc4-4.0.jar

    2.mysql 数据导入neo4j的jar包

    apoc-3.3.0.1-all.jar    mysql-connector-java-8.0.8-dmr.jar

    3.将对应jar包放在安装目录plugins文件目录里,然后conf目录里的neo4j.conf的后面加上

    1. dbms.security.procedures.unrestricted=apoc.*
    2. apoc.import.file.enabled=true
    apoc.export.file.enabled=true

    4.restart neo4j,运行return apoc.version(),若有版本号,则成功。

    三、导数据

    1. import org.neo4j.driver.v1.*;
    2. public class Connect{
    3. public static void main(String[] args){
    4. Driver driver = GraphDatabase.driver("bolt://localhost:7687",AuthTokens.basic("neo4j","neo4j"));
    5. Session session = driver.session();
    6. String cypher="create constraint on (n:ITEM) ASSERT n.itemid is unique"; //创建唯一索引,这样可以更快的导入数据
    7. Session.run(cypher);
    8. cypher="CALL apoc.periodic.iterate("CALL apoc.load.jdbc('jdbc:sqlserver://localhost;username=name;password=word;database=db;characterEncoding=utf-8',\"SELECT * FROM TABLE1\")","MERGE(n:ITEM{itemid:row.mitemid}) with * MERGE(m:ITEM{itemid:row.itemid}) with * create p=(n)-[r:rel{rels:row.rels}]->(m)",{batchSize:10000,iterateList:true})"; //连接sqlserve数据库和设计创建neo4j图数据库数据模型
    9. Session.run(cypher);
    10. session.close();
    11. driver.close();
    12. }
    13. }

    mysql数据库类似,不再赘述。

    补充:1.使用neo4j-import导入数据的命令

    neo4j-admin import --nodes:item  "nodes.csv"  --relationships:rel "rel_header.csv,rel.csv" --ignore-missing-nodes

    2.apoc 导出命令

    1. call apoc.export.cypher.query(
    2. "MATCH (p1:Person)-[r:KNOWS]->(p2:Person) RETURN p1,r,p2",
    3. "/tmp/friendships.cypher",
    4. {format:'plain',cypherFormat:'updateStructure'})`

    参考: http://neo4j-contrib.github.io/neo4j-apoc-procedures/#_export_import

    call apoc.export.cypher.query("match (n:lable) where not (n)--() and n.properties = '400' return distinct(n)","C://User/Desktop/test",{format:'plain',cypherFormat:'create'})

     3.不用解压也能导数据load csv

    load csv from "file:/twitter-2010.txt.gz" as line fieldterminator ' ' with toInt(line[0]) as id,toInt(line[1]) as id1 return id,id1 limit 10
    1. using periodic commit 1000
    2. load csv from "file:/twitter-2010.txt.gz" as line fieldterminator ' ' create (item:ITEM{id:line[0],item:line[1]})

    原文地址:https://blog.csdn.net/FFFSSSFFF6/article/details/80711202

  • 相关阅读:
    【创建图像映射】
    【用图像代替文本作为超链接】
    【设置图像的提示文字】
    【设置图像的替换文字】
    【小玩意儿:在页面上设置链接发送E-mail】
    【锚点】
    【绝对路径/相对路径】
    【安装IDEA】
    【加法计算器】
    【Unlock xcode files?】
  • 原文地址:https://www.cnblogs.com/jpfss/p/11393330.html
Copyright © 2011-2022 走看看