cypher: using IDs versus natural index

80 views
Skip to first unread message

Tomas Teicher

unread,
Apr 30, 2012, 4:34:36 PM4/30/12
to ne...@googlegroups.com
neo4j database  is natural index itself, as it is also mentioned in documentation. 
when I know IDs of nodes that I am quering, is it good practise for using statement 

START event= node(1, 12000, 5000) return event.title

should I instead use relationships (if I know them before query) to get closer to that nodes? 

For example:
START n=node(0) MATCH path = n-[:YEAR_2012]->event WHERE (ID(event) IN [1, 12000, 5000] RETURN event.title  

(I am sorry if I use wrong syntax, these command I wrote directly here as examples)

What is the better practise if I have many nodes?

thanks for any advise
Tomas


Michael Hunger

unread,
Apr 30, 2012, 4:47:26 PM4/30/12
to ne...@googlegroups.com
Tomas,

it is rather encouraged not to rely on the internal neo4j id's but use your domain specific keys, you can set them as properties and index them for faster retrieval.

It depends on your use-case how you would query them, normally index-lookups are used to find starting nodes for a traversal and then explore the graph from there.
During the traversal/cypher query you can check properties and relationships as your use-case demands.

If you need unique nodes then you can use the unique node-creation facilities of the core- or REST API.

Cheers

Michael

Tomas Teicher

unread,
May 1, 2012, 2:04:04 AM5/1/12
to ne...@googlegroups.com
thanks for answer

I don't need to set my custom values to ID. I just need to identify nodes once I select them from database.

It is quite simple to write query in Java when I know ID or Node object from previous queries.

Parameter for node object. 

Map<String, Object> params = new HashMap<String, Object>();
params.put( "node", andreasNode );
ExecutionResult result = engine.execute( "start n=node({node}) return n.name", params );

To write such query is quite handy. Is this a bad practise when I have many nodes?
should I use rather traversing a path?

thanks for answer
(I am still newbie in neo4j)
Tomas



Dňa pondelok, 30. apríla 2012 22:34:36 UTC+2 Tomas Teicher napísal(-a):

Michael Hunger

unread,
May 1, 2012, 3:41:37 AM5/1/12
to ne...@googlegroups.com
Depends on your usecase

If the neo4j id are ok for you the you can use them
Just make sure you don't store them somewhere where
they can get out of synch if nodes are deleted and recreated

You can also pass in a collection of nodes as param.




Sent from mobile device
Reply all
Reply to author
Forward
0 new messages