neography get actual node or node id from index

386 views Asked by At

I am using the below to get nodes from an index:

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

Which works fine. However, the data returned is a Hash object, as below:

> {"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}"}

I would like either the actual node object to be returned, or be able to retrieve the id easily. By id, I am referring to the integer inside http://localhost:7474/db/data/node/12.

I could get it by regex, but this surely isn't the best way?

1

There are 1 answers

0
Kaushik On

You could use the 'Phase 2' API to find it as below;

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

n.neo_id # 12