neo4j基本操作

    neo4j是目前最流行的图数据库,整体表现还是不错的。公司有些业务会把部分数据导入到neo4j,方便做一些关系/路径查询,记录一下简单的一些操作。

1 install

>> tar xvf neo4j-xxx.tar.gz
>> bin/neo4j console

2 cypher insert data

 >> CREATE(n:Person:Swedish)
 >> CREATE (alias:label:morelabel)

3 java api

<dependency>
    <groupId>org.neo4j.driver</groupId>
    <artifactId>neo4j-java-driver</artifactId>
    <version>1.4.3</version>
</dependency>

 

// 初始化驱动
Driver driver = GraphDatabase.driver("bolt://127.0.0.1:7687", 
    AuthTokens.basic("neo4j", "admin"));
// 获取一个session
Session session = driver.session();

// 执行cypher语句
session.run("create (:Person {name: kibear, age: 10})")

// 关闭连接
session.close();
driver.close();

4 create index

 

>> create index on :Person(name)
>> create index on :label(property)

 

 

 

 

猜你喜欢

转载自kibear.iteye.com/blog/2394176