Neo4j REST API使用实例—ttlsa教程系列之neo4j(二)

默北 NoSQLNeo4j REST API使用实例—ttlsa教程系列之neo4j(二)已关闭评论21,2883字数 41626阅读138分45秒阅读模式

ttlsa教程系列之neo4j---(二)Neo4j REST API使用实例
一. 简介
通过REST API方式与Neo4j进行交互式操作。请求和响应数据默认是以JSON格式展示的。需要显示设置请求头Accept: application/json请求响应数据。如果请求发送数据,需要设置Content-Type:application/json响应头。
整个REST API过程可以以JSON数据流传输,为服务器端带来更好的性能和更低的内存开销。要使用它,只需在每个请求头中加上X-Stream:true即可。

二.Nodes(节点)
1. 访问root目录
服务器根目录是REST API操作的开始点。包含数据库基本开始点,一些版本信息和扩展信息。如果设置了一个reference节点,并且该节点实际存在于数据库中,将之存在reference_node条目。
# curl -D - -H "Accept:application/json" "http://127.0.0.1:7474/db/data/" //url后面的/不能省略
HTTP/1.1 200 OK
Content-Length: 762
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"extensions" : {
"CypherPlugin" : {
"execute_query" : "http://127.0.0.1:7474/db/data/ext/CypherPlugin/graphdb/execute_query"
},
"GremlinPlugin" : {
"execute_script" : "http://127.0.0.1:7474/db/data/ext/GremlinPlugin/graphdb/execute_script"
}
},
"node" : "http://127.0.0.1:7474/db/data/node",
"node_index" : "http://127.0.0.1:7474/db/data/index/node",
"relationship_index" : "http://127.0.0.1:7474/db/data/index/relationship",
"extensions_info" : "http://127.0.0.1:7474/db/data/ext",
"relationship_types" : "http://127.0.0.1:7474/db/data/relationship/types",
"batch" : "http://127.0.0.1:7474/db/data/batch",
"cypher" : "http://127.0.0.1:7474/db/data/cypher",
"neo4j_version" : "1.8.1"
}
2. 以JSON流(以json格式化输出)
# curl -D - -H "Accept:application/json" -H "X-Stream:true" "http://127.0.0.1:7474/db/data/"
HTTP/1.1 200 OK
Content-Encoding: UTF-8
Content-Type: application/json; stream=true
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{"extensions":{"CypherPlugin":{"execute_query":"http://127.0.0.1:7474/db/data/ext/CypherPlugin/graphdb/execute_query"},"GremlinPlugin":{"execute_script":"http://127.0.0.1:7474/db/data/ext/GremlinPlugin/graphdb/execute_script"}},"node":"http://127.0.0.1:7474/db/data/node","node_index":"http://127.0.0.1:7474/db/data/index/node","relationship_index":"http://127.0.0.1:7474/db/data/index/relationship","extensions_info":"http://127.0.0.1:7474/db/data/ext","relationship_types":"http://127.0.0.1:7474/db/data/relationship/types","batch":"http://127.0.0.1:7474/db/data/batch","cypher":"http://127.0.0.1:7474/db/data/cypher","neo4j_version":"1.8.1"}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

3. 创建节点
# curl -D - -H "Accept:application/json" -X POST "http://127.0.0.1:7474/db/data/node"
HTTP/1.1 201 Created
Content-Length: 1186
Location: http://127.0.0.1:7474/db/data/node/8614011
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/8614011/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/8614011/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/8614011/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/8614011",
"properties" : "http://127.0.0.1:7474/db/data/node/8614011/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8614011/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/8614011/relationships",
"data" : {
}
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

4. 创建带属性节点
# curl -i -H "Accept:application/json" -H "Content-type: application/json" -X POST -d '{"name":"xuhh"}' "http://127.0.0.1:7474/db/data/node" // 响应头 Content-type: application/json不能省略
HTTP/1.1 201 Created
Content-Length: 1206
Location: http://127.0.0.1:7474/db/data/node/8615721
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/8615721/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/8615721/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/8615721/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/8615721",
"properties" : "http://127.0.0.1:7474/db/data/node/8615721/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/8615721/relationships",
"data" : {
"name" : "xuhh"
}
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

# curl -i -H "Content-Type: application/json" -X POST -d '{"addreess":null}' "http://127.0.0.1:7474/db/data/node" //节点属性不能为null
HTTP/1.1 400 Bad Request
Content-Length: 443
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"message" : "Could not set property \"addreess\", unsupported type: null",
"exception" : "PropertyValueException",
"stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.set(DatabaseActions.java:155)", "org.neo4j.server.rest.web.DatabaseActions.createNode(DatabaseActions.java:213)", "org.neo4j.server.rest.web.RestfulGraphDatabase.createNode(RestfulGraphDatabase.java:195)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

# curl -i -H "Content-Type: application/json" -X POST -d '{"school":{"University":"Tsinghua","senior middle school":"Experimental High School"}}' "http://127.0.0.1:7474/db/data/node" //属性值不能嵌套
HTTP/1.1 400 Bad Request
Content-Length: 505
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"message" : "Could not set property \"school\", unsupported type: {University=Tsinghua, senior middle school=Experimental High School}",
"exception" : "PropertyValueException",
"stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.set(DatabaseActions.java:155)", "org.neo4j.server.rest.web.DatabaseActions.createNode(DatabaseActions.java:213)", "org.neo4j.server.rest.web.RestfulGraphDatabase.createNode(RestfulGraphDatabase.java:195)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

5. 查看节点属性
# curl -i -H "Accept:application/json" -H "Content-type: application/json" -X GET "http://127.0.0.1:7474/db/data/node/8615721/properties"
HTTP/1.1 200 OK
Content-Length: 21
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"name" : "xuhh"
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

6.设置某个属性
# curl -i -H "Content-type: application/json" -X PUT -d '"North Boy"' "http://127.0.0.1:7474/db/data/node/8615721/properties/nickname"
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

# curl -i -H "Accept:application/json" -X GET "http://127.0.0.1:7474/db/data/node/8615721/properties"
HTTP/1.1 200 OK
Content-Length: 49
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"nickname" : "North Boy",
"name" : "xuhh"
}文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

# curl -i -H "Accept:application/json" -X GET "http://127.0.0.1:7474/db/data/node/8615721/properties/name" //查看某一属性值
HTTP/1.1 200 OK
Content-Length: 6
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

"xuhh"文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

7. 删除节点
如果该节点有relationships,将不能被删除,除非先删除relationships。
# curl -D - -H "Accept:application/json" -X DELETE http://127.0.0.1:7474/db/data/node/8614011
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

8. 获取不存在节点
# curl -D - -H "Accept:application/json" http://127.0.0.1:7474/db/data/node/8614011
HTTP/1.1 404 Not Found
Content-Length: 425
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)文章源自运维生存时间-https://www.ttlsa.com/nosql/neo4j-rest-api-2/

{
"message" : "Cannot find node with id [8614011] in database.",
"exception" : "NodeNotFoundException",
"stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.node(DatabaseActions.java:123)", "org.neo4j.server.rest.web.DatabaseActions.getNode(DatabaseActions.java:234)", "org.neo4j.server.rest.web.RestfulGraphDatabase.getNode(RestfulGraphDatabase.java:225)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}

三.Relationships(关系)
从一个节点获取关系的一般模式是:
http://IP:7474/db/data/node/node_id/relationships/{all,in,out}/{-list|&|types}
types是一个符号分隔的列表类型
1. 通过ID获取关系
# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/8615721"
HTTP/1.1 200 OK
Content-Length: 495
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"extensions" : {
},
"start" : "http://127.0.0.1:7474/db/data/node/7104006",
"property" : "http://127.0.0.1:7474/db/data/relationship/8615721/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/relationship/8615721",
"properties" : "http://127.0.0.1:7474/db/data/relationship/8615721/properties",
"type" : "Knows",
"end" : "http://127.0.0.1:7474/db/data/node/7104046",
"data" : {
"time" : 1362101805,
"name" : "得瑟瑟",
"deleted" : 0
}
}

2. 创建关系
# curl -i -H "Accept:application/json" -H "Content-type: application/json" -X POST -d '{"company":"NetDragon Websoft Inc.", "department":"Tech"}' "http://127.0.0.1:7474/db/data/node"
HTTP/1.1 201 Created
Content-Length: 1254
Location: http://127.0.0.1:7474/db/data/node/8923850
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/8923850/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/8923850/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/8923850/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/8923850",
"properties" : "http://127.0.0.1:7474/db/data/node/8923850/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8923850/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/8923850/relationships",
"data" : {
"department" : "Tech",
"company" : "NetDragon Websoft Inc."
}
}

# curl -D - -H Accept:application/json -H Content-Type:application/json -X POST -d '{"type":"EMPLOYEE","to":"http://127.0.0.1:7474/db/data/node/8923850","data":{"sex":"male","mobile":"18650365423"}}' "http://127.0.0.1:7474/db/data/node/8615721/relationships"
//"data":{"sex":"male","mobile":"18650365423"}}'是关系属性。没有的话,就是创建没有属性的关系。
HTTP/1.1 201 Created
Content-Length: 481
Location: http://127.0.0.1:7474/db/data/relationship/11068619
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"extensions" : {
},
"start" : "http://127.0.0.1:7474/db/data/node/8615721",
"property" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/relationship/11068619",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties",
"type" : "EMPLOYEE",
"end" : "http://127.0.0.1:7474/db/data/node/8923850",
"data" : {
"sex" : "male",
"mobile" : "18650365423"
}
}

3. 获取关系所有属性
# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/11068619/properties"
HTTP/1.1 200 OK
Content-Length: 48
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"mobile" : "18650365423",
"sex" : "male"
}

4. 给关系设置属性
# curl -i -H "Content-type: application/json;charset=UTF-8" -X PUT -d '"SA"' "http://127.0.0.1:7474/db/data/relationship/11068619/properties/job"
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/11068619/properties"
HTTP/1.1 200 OK
Content-Length: 64
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"job" : "SA",
"mobile" : "18650365423",
"sex" : "male"
}

5. 更改关系属性
# curl -i -H "Content-type: application/json;charset=UTF-8" -X PUT -d '"System Administrator"' "http://127.0.0.1:7474/db/data/relationship/11068619/properties/job"
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/11068619/properties"
HTTP/1.1 200 OK
Content-Length: 82
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"job" : "System Administrator",
"mobile" : "18650365423",
"sex" : "male"
}

6. 获取节点的所有关系
# curl -i -H "Accept:application/json" -H "Content-type: application/json" -X POST -d '{"name":"xiao A","nickname":"A Yi"}' "http://127.0.0.1:7474/db/data/node"
HTTP/1.1 201 Created
Content-Length: 1233
Location: http://127.0.0.1:7474/db/data/node/8932312
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

# curl -D - -H Accept:application/json -H Content-Type:application/json -X POST -d '{"type":"EMPLOYEE","to":"http://127.0.0.1:7474/db/data/node/8923850","data":{"sex":"male","mobile":"","job":"Network Administrator"}}' "http://127.0.0.1:7474/db/data/node/8932312/relationships"
HTTP/1.1 201 Created
Content-Length: 507
Location: http://127.0.0.1:7474/db/data/relationship/11078129
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8615721/relationships/all" //获取节点8615721所有关系(outcoming relationships)
HTTP/1.1 200 OK
Content-Length: 521
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"start" : "http://127.0.0.1:7474/db/data/node/8615721",
"data" : {
"sex" : "male",
"job" : "System Administrator",
"mobile" : "18650365423"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11068619",
"property" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
} ]

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8932312/relationships/all" //获取节点8932312所有关系(outcoming relationships)
HTTP/1.1 200 OK
Content-Length: 511
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"start" : "http://127.0.0.1:7474/db/data/node/8932312",
"data" : {
"sex" : "male",
"job" : "Network Administrator",
"mobile" : ""
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11078129",
"property" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
} ]

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8923850/relationships/all" //获取节点8923850所有关系(incoming relationships)
HTTP/1.1 200 OK
Content-Length: 1030
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"start" : "http://127.0.0.1:7474/db/data/node/8615721",
"data" : {
"sex" : "male",
"job" : "System Administrator",
"mobile" : "18650365423"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11068619",
"property" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
}, {
"start" : "http://127.0.0.1:7474/db/data/node/8932312",
"data" : {
"sex" : "male",
"job" : "Network Administrator",
"mobile" : ""
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11078129",
"property" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
} ]

7. 获取incoming relationships
# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8923850/relationships/in"
HTTP/1.1 200 OK
Content-Length: 1030
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"start" : "http://127.0.0.1:7474/db/data/node/8615721",
"data" : {
"sex" : "male",
"job" : "System Administrator",
"mobile" : "18650365423"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11068619",
"property" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
}, {
"start" : "http://127.0.0.1:7474/db/data/node/8932312",
"data" : {
"sex" : "male",
"job" : "Network Administrator",
"mobile" : ""
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11078129",
"property" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
} ]

8. 获取outcoming relationships
# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8923850/relationships/out"
HTTP/1.1 200 OK
Content-Length: 3
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ ]

9. 获取节点关系类型
# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/node/8923850/relationss/all/EMPLOYEE"
HTTP/1.1 200 OK
Content-Length: 1030
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"start" : "http://127.0.0.1:7474/db/data/node/8615721",
"data" : {
"sex" : "male",
"job" : "System Administrator",
"mobile" : "18650365423"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11068619",
"property" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11068619/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
}, {
"start" : "http://127.0.0.1:7474/db/data/node/8932312",
"data" : {
"sex" : "male",
"job" : "Network Administrator",
"mobile" : ""
},
"self" : "http://127.0.0.1:7474/db/data/relationship/11078129",
"property" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties",
"type" : "EMPLOYEE",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/8923850"
} ]

10. 删除关系
# curl -i -H "Content-type: application/json;charset=UTF-8" -X DELETE "http://127.0.0.1:7474/db/data/node/8932312" //删除节点前需先删除关系
HTTP/1.1 409 Conflict
Content-Length: 404
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"message" : "The node with id 8932312 cannot be deleted. Check that the node is orphaned before deletion.",
"exception" : "OperationFailureException",
"stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.deleteNode(DatabaseActions.java:255)", "org.neo4j.server.rest.web.RestfulGraphDatabase.deleteNode(RestfulGraphDatabase.java:239)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/11078129"
HTTP/1.1 200 OK
Content-Length: 507
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"extensions" : {
},
"start" : "http://127.0.0.1:7474/db/data/node/8932312",
"property" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/relationship/11078129",
"properties" : "http://127.0.0.1:7474/db/data/relationship/11078129/properties",
"type" : "EMPLOYEE",
"end" : "http://127.0.0.1:7474/db/data/node/8923850",
"data" : {
"sex" : "male",
"job" : "Network Administrator",
"mobile" : ""
}
}
# curl -i -H "Accept: application/json" -X DELETE "http://127.0.0.1:7474/db/data/relationship/11078129" //删除关系
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

# curl -i -H "Content-type: application/json;charset=UTF-8" -X GET "http://127.0.0.1:7474/db/data/relationship/11078129"
HTTP/1.1 404 Not Found
Content-Length: 392
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"exception" : "RelationshipNotFoundException",
"stacktrace" : [ "org.neo4j.server.rest.web.DatabaseActions.relationship(DatabaseActions.java:137)", "org.neo4j.server.rest.web.DatabaseActions.getRelationship(DatabaseActions.java:599)", "org.neo4j.server.rest.web.RestfulGraphDatabase.getRelationship(RestfulGraphDatabase.java:432)", "java.lang.reflect.Method.invoke(Method.java:597)" ]
}

11. 获取所有关系类型
# curl -i -H "Accept: application/json" -X GET "http://127.0.0.1:7474/db/data/relationship/types"
HTTP/1.1 200 OK
Content-Type: application/json
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Server: Jetty(6.1.25)

["LOVES","EMPLOYEE","MATRIX","KNOWS","Knows","HAS_CODED"]

四.索引(indexes)
索引可以包括nodes和relationships。通过默认配置来创建索引,在向数据库添加节点或关系时,索引将会自动创建的。什么样的默认配置取决于你如何配置数据库的。如果没有更改任何索引配置,索引将使用基于lucene的后端。
1. 创建节点索引
# curl -i -H "Content-Type: application/json" -X POST -d '{"name":"favorites"}' http://127.0.0.1:7474/db/data/index/node/
HTTP/1.1 201 Created
Content-Length: 88
Location: http://127.0.0.1:7474/db/data/index/node/favorites/
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"template" : "http://127.0.0.1:7474/db/data/index/node/favorites/{key}/{value}"
}

2. 创建节点索引配置
自定义索引配置。如果你乐于默认配置,nodes/relationships未存在的索引将会自动被创建。
# curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"name": "xuhh","config":{"type":"fulltext","provider":"lucene","to_lower_case":"false"}}' http://127.0.0.1:7474/db/data/index/node/
HTTP/1.1 201 Created
Content-Length: 160
Location: http://127.0.0.1:7474/db/data/index/node/xuhh/
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"template" : "http://127.0.0.1:7474/db/data/index/node/xuhh/{key}/{value}",
"type" : "fulltext",
"provider" : "lucene",
"to_lower_case" : "false"
}

3. 列出节点索引
# curl -i -H "Accept: application/json" http://127.0.0.1:7474/db/data/index/node/
HTTP/1.1 200 OK
Content-Length: 623
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"xuhh" : {
"to_lower_case" : "false",
"template" : "http://127.0.0.1:7474/db/data/index/node/xuhh/{key}/{value}",
"provider" : "lucene",
"type" : "fulltext"
},
"vertices" : {
"template" : "http://127.0.0.1:7474/db/data/index/node/vertices/{key}/{value}",
"_blueprints:type" : "AUTOMATIC",
"provider" : "lucene",
"_blueprints:autokeys" : "null",
"type" : "exact"
},
"node_auto_index" : {
"template" : "http://127.0.0.1:7474/db/data/index/node/node_auto_index/{key}/{value}",
"_blueprints:type" : "MANUAL",
"provider" : "lucene",
"type" : "exact"
}
}

4. 删除节点索引
# curl -i -H "Accept: application/json" -X DELETE http://127.0.0.1:7474/db/data/index/node/favorites
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

5. 向索引添加节点
在给定的索引中以key-value键值对与节点关联。
# curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"value":"v1", "uri":"http://127.0.0.1:7474/db/data/node/8615721","key":"k1"}' http://127.0.0.1:7474/db/data/index/node/xuhh
HTTP/1.1 201 Created
Content-Length: 1316
Location: http://127.0.0.1:7474/db/data/index/node/xuhh/k1/v1/8615721
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/8615721/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/8615721/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/8615721/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/8615721",
"properties" : "http://127.0.0.1:7474/db/data/node/8615721/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/8615721/relationships",
"data" : {
"nickname" : "North Boy",
"name" : "xuhh"
},
"indexed" : "http://127.0.0.1:7474/db/data/index/node/xuhh/k1/v1/8615721"
}

6. 查找完全匹配的节点
# curl -i -H "Accept: application/json" http://127.0.0.1:7474/db/data/index/node/xuhh/k1/v1
HTTP/1.1 200 OK
Content-Length: 1320
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"indexed" : "http://127.0.0.1:7474/db/data/index/node/xuhh/k1/v1/8615721",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out",
"data" : {
"nickname" : "North Boy",
"name" : "xuhh"
},
"traverse" : "http://127.0.0.1:7474/db/data/node/8615721/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/8615721/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/node/8615721",
"properties" : "http://127.0.0.1:7474/db/data/node/8615721/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in",
"extensions" : {
},
"create_relationship" : "http://127.0.0.1:7474/db/data/node/8615721/relationships",
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/8615721/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/all",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/8615721/relationships/in/{-list|&|types}"
} ]

7. 通过查询寻找节点(后面说)

8. 给定node和key从index删除所有条目
# curl -i -H "Accept: application/json" -X DELETE http://127.0.0.1:7474/db/data/index/node/xuhh/k1/8615721
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

9. 给定node,key和value从index删除所有条目
# curl -i -H "Accept: application/json" -X DELETE http://127.0.0.1:7474/db/data/index/node/xuhh/k1/v1/8615721
HTTP/1.1 204 No Content
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

五.自动索引
Neo4j为node和relationships提供了一个单独的index,当数据库元素发生增删改时,自动跟踪属性值。这种功能称为自动索引,可以通过数据库配置文件和API方式控制。
默认情况下,node和relationships的自动索引是不启用的。要启用更改neo4j.properties配置文件:
# Enable auto-indexing for nodes, default is false
node_auto_indexing=true
# The node property keys to be auto-indexed, if enabled
node_keys_indexable=uid,mobile,guid //根据实际情况更改
# Enable auto-indexing for relationships, default is false
#relationship_auto_indexing=true
# The relationship property keys to be auto-indexed, if enabled
#relationship_keys_indexable=name,age //根据实际情况更改

# curl -i -H "Accept: applicaiont/json" -XGET http://127.0.0.1:7474/db/data/index/node/node_auto_index/uid?query=30408476
HTTP/1.1 200 OK
Content-Length: 1259
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ {
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/out",
"data" : {
"uid" : 30408476,
"show" : 1,
"mobile" : "8615885057075"
},
"traverse" : "http://127.0.0.1:7474/db/data/node/9258174/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/9258174/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/node/9258174",
"properties" : "http://127.0.0.1:7474/db/data/node/9258174/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/in",
"extensions" : {
},
"create_relationship" : "http://127.0.0.1:7474/db/data/node/9258174/relationships",
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/9258174/paged/traverse/{returnType}{?pageSize,leaseTime}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/all",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/9258174/relationships/in/{-list|&|types}"
} ]

1. 为nodes创建自动索引
# curl –i -H “Accept: application/json” -H “Content-Type: application/json” -d ‘{“name”:”node_auto_index”,”config”:{“type”:”fulltext”,”provider”:”lucene”}}’ http://127.0.0.1:7474/db/data/index/node/

2. 为relationships创建自动索引
# curl -i -H “Accept: application/json” -H “Content-Type: application/json” -d ‘{“name”:”relationship_auto_index”,”config”:{“type”:”fulltext”,”provider”:”lucene”}}’ http://127.0.0.1:7474/db/data/index/relationship/

3. 获取当前nodes节点索引状态
# curl -i -H "Accept: applicaiont/json" -XGET http://127.0.0.1:7474/db/data/index/auto/node/status
HTTP/1.1 200 OK
Content-Length: 4
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

true

4.更改node索引状态
# curl -i -H "Accept: applicaiont/json" -H “Content-Type: application/json” -d “false” –X PUT http://127.0.0.1:7474/db/data/index/auto/node/status //false关闭,true启动

5. 获取当前relationship索引状态
# curl -i -H "Accept: applicaiont/json" -XGET http://127.0.0.1:7474/db/data/index/auto/relationship/status
HTTP/1.1 200 OK
Content-Length: 5
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

false

6.更改node索引状态
# curl -i -H "Accept: applicaiont/json" -H “Content-Type: application/json” -d “false” –X PUT http://127.0.0.1:7474/db/data/index/auto/relationship/status //false关闭,true启动

7. 查找node自动索引属性(键)
# curl -i -H "Accept: applicaiont/json" -XGET http://127.0.0.1:7474/db/data/index/auto/node/properties
HTTP/1.1 200 OK
Content-Length: 27
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ "uid", "guid", "mobile" ]

8. 查找relationship自动索引属性(键)
# curl -i -H "Accept: applicaiont/json" -XGET http://127.0.0.1:7474/db/data/index/auto/relationship/properties //空,未定义
HTTP/1.1 200 OK
Content-Length: 3
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: Jetty(6.1.25)

[ ]

9. 更改node自动索引属性(键) (服务重启后失效)
# curl -i -H "Content-Type: application/json" -H "Accept: application/json" -d "property_key" -XPOST http://127.0.0.1:7474/db/data/index/auto/node/properties //添加
# curl -i -H "Accept: application/json" -d "property_key" -X DELETE http://127.0.0.1:7474/db/data/index/auto/node/properties //删除

10. 更改relationship自动索引属性(键) (服务重启后失效)
# curl -i -H "Content-Type: application/json" -H "Accept: application/json" -d "property_key" -XPOST http://127.0.0.1:7474/db/data/index/auto/relationship/properties //添加
# curl -i -H "Accept: application/json" -d "property_key" -X DELETE http://127.0.0.1:7474/db/data/index/auto/relationship/properties //删除

六. 遍历(Traversals)
遍历从一个node开始执行,由URI和请求的主体控制。
returnType: 在响应对象中以traverse/{returnType}构成URL。
returnType值有一下之一:
node
relationship
path: 包含起始和终止节点的完整描述,其余是URIs。
fullpath: 包含所有nodes和replications的完整描述。

要决定在图数据库中如何遍历的,可在请求体中设置如下参数:
order: 决定访问nodes顺序,值有breadth_first(BFS广论优先搜索), depth_first(DFS深度优先搜索)
relationships: 决定何种关系类型和关系方向,方向值有all,in,out
uniqueness: 决定如何计算唯一性,值有node_global, nono, relationship_global, node_path, relationship_path
prune_evaluator(修剪评判者): 决定traverser是否继续沿着这条path接着走或是被修剪不需要继续沿着这条path走下去。你可以none内置的修剪评判者写自己的修剪评判者。
return_filter: 决定当前位置是否应该包含在结果中。可以使用自己的过滤代码或使用内置过滤器all,all_but_start_node。
max_depth: 指定到达多少深度后修剪评判者开始修剪。如果没有指定最大深度是1,如果指定prune_evaluator代替了max_depth,将没有设置最大深度限制。

七. 内置的图论算法
Neo4j内置了一些图形算法,从起始节点执行。遍历由URI和请求的主体来控制。
algorithm: 默认算法是shortestPath。
算法有:
shortestPath
allSimplePaths
allPaths
dijkstra(参数有cost_property,default_cost)
max_depth: 最大深度,默认为1,像ShortestPath算法。

八.批处理
将多条API调用并行到单个HTTP调用,显著提高大量插入和更新操作性能。要执行的任务需是以JSON格式的,整个过程是事务的,任何一条操作执行失败(返回HTTP状态码非2XX)都将回滚。
任务描述格式需要包含to和method属性。to属性值是相对于数据API根,method属性值是HTTP请求方法。如:
[{“method” : ”PUT”, ”to” : “/node/0/properties”, ”body” : {“age” :1 }, “id” : 0}]
解释如下:键是关键字。
“method” : ”PUT” : HTTP方法
”to” : “/node/0/properties” : 目的RUL
”body” : {“age” :1 } : 请求体。请求体中的值是json格式的。
“id” : 0 : 请求ID,用以标示的,在同一个批处理中,{[job id]}做为特殊语法在子任务中注入。

<?php
$json = array(array("method" => "POST", "to" => "/node", "body" => array("name" => "Tech department","lead" => "Mr. Wu"),"id" => 0),
array("method" => "GET", "to" => "{0}/proterties", "id" => 1)
);
var_dump(json_encode($json));
?>

# curl -i -H "Accept: application/json" -H "Conten-Type: applicatin/json" -XPOST -d '[{"method":"POST","to":"/node","body":{"name":"Tech department","lead":"Mr. Wu"},"id":0},{"method":"GET","to":"{0}/properties","id":1}]' http://127.0.0.1:7474/db/data/batch
HTTP/1.1 200 OK
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Server: Jetty(6.1.25)

[{"id":0,"location":"http://127.0.0.1:7474/db/data/node/3385","body":{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/3385/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/3385/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/3385/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/3385",
"properties" : "http://127.0.0.1:7474/db/data/node/3385/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3385/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/3385/relationships",
"data" : {
"name" : "Tech department",
"lead" : "Mr. Wu"
}
},"from":"/node"},
{"id":1,"body":{
"lead" : "Mr. Wu",
"name" : "Tech department"
},"from":"http://127.0.0.1:7474/db/data/node/3385/properties"}]

<?php

$json = array(array("method" => "POST", "to" => "/node", "body" => array("name" => "Tech department","lead" => "Mr. Wu"),"id" => 0),
array("method" => "GET", "to" => "{0}", "id" => 1),
array("method" => "GET", "to" => "{0}/relationships/all", "id" => 2),
array("method" => "POST", "to" => "/node", "body" => array("name" => "Web Ops"), "id" => 3),
array("method" => "GET", "to" => "{3}", "id" => 4),
array("method" => "GET", "to" => "{3}/relationships/all", "id" => 5),
array("method" => "POST", "to" => "{0}/relationships", "body" => array("to" => "{3}", "type" => "DEPT", "data" => array("lead" => "Mr. Wu")), "id" => 6),
array("method" => "GET", "to" => "{0}/relationships/all", "id" => 7),
array("method" => "GET", "to" => "{3}/relationships/all", "id" => 8)

);
var_dump(json_encode($json));
?>

# curl -i -H "Accept: application/json" -H "Conten-Type: applicatin/json" -XPOST -d '[{"method":"POST","to":"/node","body":{"name":"Tech department","lead":"Mr. Wu"},"id":0},{"method":"GET","to":"{0}","id":1},{"method":"GET","to":"{0}/relationships/all","id":2},{"method":"POST","to":"/node","body":{"name":"Web Ops"},"id":3},{"method":"GET","to":"{3}","id":4},{"method":"GET","to":"{3}/relationships/all","id":5},{"method":"POST","to":"{0}/relationships","body":{"to":"{3}","type":"DEPT","data":{"lead":"Mr. Wu"}},"id":6},{"method":"GET","to":"{0}/relationships/all","id":7},{"method":"GET","to":"{3}/relationships/all","id":8}]' http://127.0.0.1:7474/db/data/batch
HTTP/1.1 200 OK
Content-Encoding: UTF-8
Content-Type: application/json
Access-Control-Allow-Origin: *
Transfer-Encoding: chunked
Server: Jetty(6.1.25)

[{"id":0,"location":"http://127.0.0.1:7474/db/data/node/3386","body":{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/3386/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/3386/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/3386/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/3386",
"properties" : "http://127.0.0.1:7474/db/data/node/3386/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/3386/relationships",
"data" : {
"name" : "Tech department",
"lead" : "Mr. Wu"
}
},"from":"/node"},
{"id":1,"body":{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/3386/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/3386/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/3386/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/3386",
"properties" : "http://127.0.0.1:7474/db/data/node/3386/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3386/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/3386/relationships",
"data" : {
"name" : "Tech department",
"lead" : "Mr. Wu"
}
},"from":"http://127.0.0.1:7474/db/data/node/3386"},
{"id":2,"body":[ ],"from":"http://127.0.0.1:7474/db/data/node/3386/relationships/all"},
{"id":3,"location":"http://127.0.0.1:7474/db/data/node/3387","body":{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/3387/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/3387/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/3387/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/3387",
"properties" : "http://127.0.0.1:7474/db/data/node/3387/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/3387/relationships",
"data" : {
"name" : "Web Ops"
}
},"from":"/node"},
{"id":4,"body":{
"extensions" : {
},
"paged_traverse" : "http://127.0.0.1:7474/db/data/node/3387/paged/traverse/{returnType}{?pageSize,leaseTime}",
"outgoing_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/out",
"traverse" : "http://127.0.0.1:7474/db/data/node/3387/traverse/{returnType}",
"all_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/all/{-list|&|types}",
"property" : "http://127.0.0.1:7474/db/data/node/3387/properties/{key}",
"all_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/all",
"self" : "http://127.0.0.1:7474/db/data/node/3387",
"properties" : "http://127.0.0.1:7474/db/data/node/3387/properties",
"outgoing_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/out/{-list|&|types}",
"incoming_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/in",
"incoming_typed_relationships" : "http://127.0.0.1:7474/db/data/node/3387/relationships/in/{-list|&|types}",
"create_relationship" : "http://127.0.0.1:7474/db/data/node/3387/relationships",
"data" : {
"name" : "Web Ops"
}
},"from":"http://127.0.0.1:7474/db/data/node/3387"},
{"id":5,"body":[ ],"from":"http://127.0.0.1:7474/db/data/node/3387/relationships/all"},
{"id":6,"location":"http://127.0.0.1:7474/db/data/relationship/8096","body":{
"extensions" : {
},
"start" : "http://127.0.0.1:7474/db/data/node/3386",
"property" : "http://127.0.0.1:7474/db/data/relationship/8096/properties/{key}",
"self" : "http://127.0.0.1:7474/db/data/relationship/8096",
"properties" : "http://127.0.0.1:7474/db/data/relationship/8096/properties",
"type" : "DEPT",
"end" : "http://127.0.0.1:7474/db/data/node/3387",
"data" : {
"lead" : "Mr. Wu"
}
},"from":"http://127.0.0.1:7474/db/data/node/3386/relationships"},
{"id":7,"body":[ {
"start" : "http://127.0.0.1:7474/db/data/node/3386",
"data" : {
"lead" : "Mr. Wu"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/8096",
"property" : "http://127.0.0.1:7474/db/data/relationship/8096/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/8096/properties",
"type" : "DEPT",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/3387"
} ],"from":"http://127.0.0.1:7474/db/data/node/3386/relationships/all"},
{"id":8,"body":[ {
"start" : "http://127.0.0.1:7474/db/data/node/3386",
"data" : {
"lead" : "Mr. Wu"
},
"self" : "http://127.0.0.1:7474/db/data/relationship/8096",
"property" : "http://127.0.0.1:7474/db/data/relationship/8096/properties/{key}",
"properties" : "http://127.0.0.1:7474/db/data/relationship/8096/properties",
"type" : "DEPT",
"extensions" : {
},
"end" : "http://127.0.0.1:7474/db/data/node/3387"
} ],"from":"http://127.0.0.1:7474/db/data/node/3387/relationships/all"}]
九.Cypher插件(参考Cypher语言,后面再说)

十.Gremlin插件(小妖精插件)
Gremlin是一个基于Groovy的图遍历语言,提供一个非常明确的脚本来遍历图的表达方式。
Neo4j的Gremlin插件提供了一个端点向Neo4j服务发送Gremlin脚本。该脚本在数据库上执行,node和relationship表示作为结果返回或只返回指定属性。与REST API类型保持一致。

weinxin
我的微信
微信公众号
扫一扫关注运维生存时间公众号,获取最新技术文章~
默北
  • 本文由 发表于 24/06/2013 14:01:03
  • 转载请务必保留本文链接:https://www.ttlsa.com/nosql/neo4j-rest-api-2/