2014-09-29 48 views
0

我正在使用neo4jrestclient库。neo4jrestclient - 查询获取ID

from neo4jrestclient.client import GraphDatabase 
from neo4jrestclient import client 
from neo4jrestclient import query 
gdb = GraphDatabase("http://localhost:7474/db/data/") 
q = """MATCH n RETURN n;""" 
result = gdb.query(q=q) 
print(result[0]) 

当我执行查询“MATCH返回n n,则输出是:

[{ 
'all_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all', 
'all_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/all/{-list|&|types}', 
'self': 'http://localhost:7474/db/data/node/1131', 
'labels': 'http://localhost:7474/db/data/node/1131/labels', 
'properties': 'http://localhost:7474/db/data/node/1131/properties', 
'create_relationship': 'http://localhost:7474/db/data/node/1131/relationships', 
'outgoing_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out', 
'data': { 
    'title': 'title', 
    'name': 'Poludnie' 
}, 
'incoming_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in/{-list|&|types}', 
'property': 'http://localhost:7474/db/data/node/1131/properties/{key}', 
'paged_traverse': 'http://localhost:7474/db/data/node/1131/paged/traverse/{returnType}{?pageSize,leaseTime}', 
'incoming_relationships': 'http://localhost:7474/db/data/node/1131/relationships/in', 
'outgoing_typed_relationships': 'http://localhost:7474/db/data/node/1131/relationships/out/{-list|&|types}', 
'traverse': 'http://localhost:7474/db/data/node/1131/traverse/{returnType}'}] 

我看到节点的ID = 1131的问题是:我能获得这个ID在生?没有这些链接的形式,我想用“数据”字段的值一起都只有ID

回答

1

在Cypher支架,其可以表达如下:

MATCH (n) RETURN {id: ID(n), name: n.name, title: n.title} as city 

在响应中,该data散列将包含一个阵列,并且每个元件的row键将使用其给定的密钥包含可访问这些数据。

1

得到“公正的ID和数据,更改查询:

MATCH (n) RETURN id(n), n.data 

看看这是否令人满意。