一.安装
可以详细参考:Neo4j下载安装以及Neo4j浏览器详细说明
打开neo4j的方式,在命令行输入 neo4j.bat console
(以下内容来自neo4j的介绍内容,在这里整理出来)
桌面版可以看图数据库初探——2. neo4j安装和简单使用
二.概念指导
1.基础概念
- Nodes :represent entities of a domain.
- Labels: shape the domain by grouping nodes into sets. Relationships - connect two nodes.
- Properties:named values that add qualities to nodes and
relationships.
其中:
- Nodes often represents entities(实体) or discrete objects(离散对象) that can be classified with zero or more labels.
- Data is stored as properties of the nodes.(数据作为属性存储在对象中)
- Properties are simple key-value pairs.(属性是简单键值对)
2.标签-对节点分类
Nodes can be grouped together by applying a Label to each member. In this social graph, you label each node that represents a Person.
- A node can have zero or more labels.
- Labels are used to classify nodes.
- 相同标签的节点可以有不同的属性值
3.关系
代表Emil knows Johan and Ian.
1.概念
- Relationships always have a direction.
- Relationships always have a type.
- Relationships form patterns of data, the structure of the graph.(关系形成数据的模式,即图表的结构。)
2.关系的属性
- 关系也可以有属性来描述
- 统一个type可以有不同的属性
三.cypher语言简单介绍
详细可以参考Neo4j 第三篇:Cypher查询入门
1.CREATE
CREATE (ee:Person {name: 'Emil', from: 'Sweden', kloutScore: 99})
- CREATE :creates the node.
- () :括号代表节点
- ee:Person : ee 是节点变量名 ,Person 是节点标签
- {} :包含描述节点的属性
2.MATECH
MATCH (ee:Person) WHERE ee.name = 'Emil' RETURN ee;
- MATCH :specifies a pattern of nodes and relationships.
- (ee:Person) :将标签是Person的节点赋值给ee
- WHERE :后面写查询条件(从ee中选出符合查询条件的节点).
- ee.name = ‘Emil’ :选出属性name=EMil的节点
MATCH (ee:Person)-[:KNOWS]-(friends)
WHERE ee.name = 'Emil' RETURN ee, friends
- MATCH: describes what nodes will be retrieved based upon the pattern.
(ee) :is the node reference that will be returned based upon the WHERE clause.(ee代表:带Person标签且where条件中筛选出来的节点) - -[:KNOWS]-: matches the KNOWS relationships (in either direction) from ee.(在从ee的全部关系匹配KOWNS关系)
(friends): represents the nodes that are Emil’s friends.
RETURN: returns the node, referenced here by (ee), and the related (friends) nodes found.
代码示例
MATCH (ee:Person) WHERE ee.name = 'Emil'
CREATE (js:Person { name: 'Johan', from: 'Sweden', learn: 'surfing' }),
(ir:Person { name: 'Ian', from: 'England', title: 'author' }),
(rvb:Person { name: 'Rik', from: 'Belgium', pet: 'Orval' }),
(ally:Person { name: 'Allison', from: 'California', hobby: 'surfing' }),
(ee)-[:KNOWS {since: 2001}]->(js),(ee)-[:KNOWS {rating: 5}]->(ir),
(js)-[:KNOWS]->(ir),(js)-[:KNOWS]->(rvb),
(ir)-[:KNOWS]->(js),(ir)-[:KNOWS]->(ally),
(rvb)-[:KNOWS]->(ally)
一些示例的查询语句
#Find the actor named "Tom Hanks":
MATCH (tom:Person {name: "Tom Hanks"}) RETURN tom
#Find the movie with title "Cloud Atlas":
MATCH (cloudAtlas:Movie {title: "Cloud Atlas"}) RETURN cloudAtlas
#Find 10 people and return their names:
MATCH (people:Person) RETURN people.name LIMIT 10
#Find movies released in the 1990s and return their titles.
MATCH (nineties:Movie) WHERE nineties.released >= 1990 AND nineties.released < 2000 RETURN nineties.title
#What movies did Tom Hanks act in?
MATCH (tom:Person {name: "Tom Hanks"})-[:ACTED_IN]->(tomHanksMovies) RETURN tom,tomHanksMovies
#Who directed "Cloud Atlas"?
MATCH (cloudAtlas:Movie {title: "Cloud Atlas"})<-[:DIRECTED]-(directors) RETURN directors.name
#Who were Tom Hanks' co-actors?
MATCH (tom:Person {name:"Tom Hanks"})-[:ACTED_IN]->(m)<-[:ACTED_IN]-(coActors) RETURN DISTINCT coActors.name
#How people are related to "Cloud Atlas"?
MATCH (people:Person)-[relatedTo]-(:Movie {title: "Cloud Atlas"}) RETURN people.name, Type(relatedTo), relatedTo.roles
3.创建约束(constraint)
创建唯一的节点属性约束,以确保属性值对于具有特定标签的所有节点都是唯一的。添加唯一约束,隐式地在该属性上添加索引。
(movie是个标签,title是个属性)
CREATE CONSTRAINT ON (n:Movie) ASSERT (n.title) IS UNIQUE
4.创建索引(index nodes)
为具有给定标签的所有节点创建一个或多个属性的索引。索引用于提高搜索性能。
CREATE INDEX FOR (m:Movie) ON (m.released)
5.删除
NOTE: Nodes cannot be deleted if they have relationships, so you need to detach the nodes to delete them.
#Delete all Movie and Person nodes, and their relationships.
MATCH (n) DETACH DELETE n
#Verify that the Movie Graph has been removed.
MATCH (n) RETURN n
四.忘记密码
才过了一天就忘记了用户名和密码。。。。
删除auth文件,再重新启动,输入默认密码neo4j后,就会跳转到让重置密码
五.远程访问
1.修改配置文件
修改conf文件中的
2.开放防火前入站规则
可以参考Windows系统如何在防火墙里开放端口
因为我只修改了7474端口,所以我开放了7474.
3.访问X.X.X.X:7474
(其中X.X.X.X为本地计算机IP)