neography从索引获取实际节点或节点id

时间:2013-09-11 11:07:47

标签: graph nosql neo4j neography

我使用以下内容从索引中获取节点:

neo.get_node_index('nodes_index', 'type', 'repo')

哪个工作正常。但是,返回的数据是Hash对象,如下所示:

> {"indexed"=>"http://localhost:7474/db/data/index/node/nodes_index/type/repo/12", "outgoing_relationships"=>"http://localhost:7474/db/data/node/12/relationships/out",
> "data"=>{"name"=>"irc-logs"},
> "traverse"=>"http://localhost:7474/db/data/node/12/traverse/{returnType}",
> "all_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/all/{-list|&|types}",
> "property"=>"http://localhost:7474/db/data/node/12/properties/{key}",
> "self"=>"http://localhost:7474/db/data/node/12",
> "properties"=>"http://localhost:7474/db/data/node/12/properties",
> "outgoing_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/out/{-list|&|types}",
> "incoming_relationships"=>"http://localhost:7474/db/data/node/12/relationships/in",
> "extensions"=>{},
> "create_relationship"=>"http://localhost:7474/db/data/node/12/relationships", "paged_traverse"=>"http://localhost:7474/db/data/node/12/paged/traverse/{returnType}{?pageSize,leaseTime}",
> "all_relationships"=>"http://localhost:7474/db/data/node/12/relationships/all",
> "incoming_typed_relationships"=>"http://localhost:7474/db/data/node/12/relationships/in/{-list|&|types}"}

我想要返回实际的节点对象,或者能够轻松地检索id。通过id,我指的是http://localhost:7474/db/data/node/12内的整数。

我可以通过正则表达式得到它,但这肯定不是最好的方法吗?

1 个答案:

答案 0 :(得分:2)

您可以使用'Phase 2' API找到它,如下所示;

n = Neography::Node.find('nodes_index', 'type', 'repo')

n.neo_id # 12