图形数据库之---neo4j(非关系型数据库)
Neo4j是一个高性能的,NOSQL图形数据库,它将结构化数据存储在网络上而不是表中。Neo4j也可以被看作是一个高性能的图引擎,该引擎具有成熟数据库的所有特性。程序员工作在一个面向对象的、灵活的网络结构下而不是严格、静态的表中——但是他们可以享受到具备完全的事务特性、企业级的数据库的所有好处。
Neo4j因其嵌入式、高性能、轻量级等优势,越来越受到关注。
在一个图中包含两种基本的数据类型:Nodes(节点) 和 Relationships(关系)。Nodes 和 Relationships 包含key/value形式的属性。Nodes通过Relationships所定义的关系相连起来,形成关系型网络结构。
neo4j是一种图数据库,同时它也是一种嵌入式数据库。它对图数据是以节点和边(关系)模式进行存储。每个节点可以包含一系列信息,通过Node类里面的setProperty()方法对节点信息进行存储,Node也可以使用createRelationshipTo()方法实现个节点和其他节点的联系,并且该方法返回的是一个Relationship对象,我们也可以对Relationship设置属性,也就是节点和节点之间的关系属性。什么叫关系属性?例如:person1àperson2,person1和person2的关系可以是朋友也可以是同学还可以是亲人,这里的朋友、同学、亲人就是这里的Relationship的属性。那么关系属性就是描叙两个节点之间的关系类型。这就方便在对节点进行查找的时候对节点进行过滤。
neo4j数据库中的节点类似关系型数据库中的表。neo4j节点之间的关系类似关系型数据库中的2表之间的第三张表,neo4j数据库的节点之间的关系上也可以保存一些2者之间关系的属性键值对。同样,可以为每种关系创建一个名字,把关系归类管理。图形数据库比关系型性能好很多,操作性很好,可以灵活的控制,根据neo4j中Node的不同,我们可以赋予不同的属性
http://docs.neo4j.org/refcard/2.0/
START
n=
node
(*)
START
n=
node
({ids})
START
n=
node
({id1}), m=
node
({id2})
START
n=
node
:nodeIndexName(key={value})
node_auto_indexfor the automatic index.MATCH
(n:Person)-[:KNOWS]->(m:Person)
WHERE
n.name=
"Alice"
START clause is required then.MATCH
(n)-->(m)
MATCH except the ones containing property maps.MATCH
p = (n)-->(m)
p.WHERE
n.property <> {value}
n.property <> {value}
has
(n.property)
n.number >= 1
AND
n.number <= 10
n:Person
identifier
IS
NULL
NULL.NOT
has
(n.property)
OR
n.property = {value}
TRUE.n.property = {value}
NULL, which is only equal to NULL.n.property =~
"Tob.*"
(n)-[:KNOWS]->(m)
NOT
(n)-[:KNOWS]->(m)
(n)-[:KNOWS]->(m) from the result.n.property
IN
[{value1}, {value2}]
all
(x
IN
collection
WHERE
has
(x.property))
true if the predicate is TRUE for all elements of the collection.any
(x
IN
collection
WHERE
has
(x.property))
true if the predicate is TRUE for at least one element of the collection.none
(x
IN
collection
WHERE
has
(x.property))
TRUE if the predicate is FALSE for all elements of the collection.single
(x
IN
collection
WHERE
has
(x.property))
TRUE if the predicate is TRUE for exactly one element in the collection.length
(collection)
type
(a_relationship)
startNode
(a_relationship)
endNode
(a_relationship)
coalesce
(n.property, {defaultValue})
NULL expression.head
(collection)
last
(collection)
timestamp
()
id
(node_or_relationship)
str
({expression})
replace
({original}, {search}, {replacement})
search with replacement. All arguments are be expressions.substring
({original}, {begin}, {sub_length})
sub_length argument is optional.left
({original}, {sub_length}),
right
({original}, {sub_length})
trim
({original}),
ltrim
({original}),
rtrim
({original})
upper
({original}),
lower
({original})
RETURN
*
RETURN
n
AS
columnName
RETURN
DISTINCT
n
ORDER
BY
n.property
ORDER
BY
n.property
DESC
SKIP
{skip_number}
LIMIT
{limit_number}
SKIP
{skip_number}
LIMIT
{limit_number}
MATCH
(user)-[:FRIEND]-(friend)
WHERE
user.name = {name}
WITH
user,
count
(friend)
AS
friends
WHERE
friends > 10
RETURN
user
WITH syntax is similar to RETURN. It separates query parts explicitly, allowing you to declare which identifiers to carry over to the next part.MATCH
(user)-[:FRIEND]-(friend)
WITH
user,
count
(friend)
AS
friends
ORDER
BY
friends
DESC
SKIP
1
LIMIT
3
RETURN
user
ORDER BY, SKIP, LIMIT with WITH.CASE
n.eyes
WHEN
'blue'
THEN
1
WHEN
'brown'
THEN
2
ELSE
3
END
THEN value from the matching WHEN value. TheELSE value is optional, and substituted for NULL if missing.CASE
WHEN
n.eyes =
'blue'
THEN
1
WHEN
n.age < 40
THEN
2
ELSE
3
END
THEN value from the first WHEN predicate evaluating to TRUE. Predicates are evaluated in order.labels
(n)
nodes
(path)
relationships
(path)
extract
(x
IN
coll | x.prop)
filter
(x
IN
coll
WHERE
x.prop <> {value})
TRUE.tail
(coll)
range
({first_num}, {last_num}, {step})
step argument is optional.reduce
(s =
""
, n
IN
coll | s + n.prop)
FOREACH
(n
IN
coll |
SET
n.marked =
TRUE
)
count
(*)
count
(identifier)
NULL values.count
(
DISTINCT
identifier)
DISTINCTmodifier, which removes duplicates from the values.sum
(n.property)
avg
(n.property)
max
(n.property)
min
(n.property)
collect
(n.property)
NULL.percentile_disc
(n.property, {percentile})
percentile argument is from 0.0to 1.0.percentile_cont
(n.property, {percentile})
stdev
(n.property)
stdevp
(n.property)
(
CREATE
[
UNIQUE
] |
MERGE
)*
[
SET
|
DELETE
|
FOREACH
]*
[
RETURN
[
ORDER
BY
] [
SKIP
] [
LIMIT
]]
[
START
]
[
MATCH
]
[
WHERE
]
[
WITH
[
ORDER
BY
] [
SKIP
] [
LIMIT
]]
[
CREATE
[
UNIQUE
]|
MERGE
]*
[
SET
|
DELETE
|
FOREACH
]*
[
RETURN
[
ORDER
BY
] [
SKIP
] [
LIMIT
]]
CREATE
(n {name: {value}})
CREATE
(n {map})
CREATE
(n {collectionOfMaps})
CREATE
(n)-[r:KNOWS]->(m)
CREATE
(n)-[:LOVES {since: {value}}]->(m)
CREATE
UNIQUE
(n)-[:KNOWS]->(m {property: {value}})
MERGE
(n:Person {property: {value}})
ON
CREATE
n
SET
n.created =
timestamp
()
ON
MATCH
n
SET
n.access = n.access+1
ON CREATE n and ON MATCH n for conditional updates.SET
n.property={value}
SET
n={map}
SET
n:Person
Person to a node.DELETE
n, r
REMOVE
n:Person
n.REMOVE
n.property
CREATE
INDEX
ON
:Person(name)
Person and property name.DROP
INDEX
ON
:Person(name)
Person and property name.MATCH
(n:Person)
WHERE
n.name = {value}
lower(n.name) = {value} will not use an index.abs
({expr})
rand
()
round
({expr})
floor
({expr})
ceil
({expr})
sqrt
({expr})
sign
({expr})
0 if zero, -1 if negative, 1 if positive.sin
({expr})
cos, tan, cot, asin, acos,atan, atan2({y-expr}, x-expr}).degrees
({expr}),
radians
({expr}),
pi
()
radians for the reverse. pi for π.log10
({expr}),
log
({expr}),
exp
({expr}),
e
()
e to the power of the parameter. Value of e.