2

I'm using Gremlin with Java and a Neo4j graph. I create 3 new vertices and try to set their Ids to 1,2,3 but it does not seem to be working, what am I doing wrong?

Vertex v1 = g.addVertex(1);
v1.setProperty("name","jim");
Vertex v2 = g.addVertex(2);
v2.setProperty("name","bob");
Vertex v3 = g.addVertex(3);
v3.setProperty("name","fred");

//iterate through the vertices and get their id's (shouldn't they be 1,2, and 3 ??

for (Vertex V:GVs)
    System.out.println(V.getId());

returns:

15
16
17

Why is this? How can I set the Ids to 1,2,3? Also can I set the Ids to strings instead?

Thanks!

user1056805
  • 2,633
  • 5
  • 21
  • 19

1 Answers1

3

Neo4j is assigning the IDs of new data for you, you can't set them, except when you use the BatchInserter utility. Gremlin is silently ignoring your IDs.

Peter Neubauer
  • 6,311
  • 1
  • 21
  • 24
  • Oh ok interesting. So if I want to assign a node an Id then I could set it as a property, but then how would I efficiently lookup the node associated with that Id? Is there a better way than getting all nodes in the graph and then filter by the property Id? – user1056805 Apr 26 '12 at 13:57
  • Yes, you can index that property and look it up, see http://docs.neo4j.org/chunked/snapshot/indexing.html – Peter Neubauer Apr 30 '12 at 06:08