Michail Michailidis
Michail Michailidis

Reputation: 12171

how to query by vertex id in Datastax DSE 5.0 Graph in a concise way?

It seems that the unique id for vertices is community_id in DSE Graph.

I have found that this works (id is long) :

   v = g.V().has("VertexLabel","community_id",id).next()

none of those work:

   v = g.V("community_id",id).next()
   v = g.V("community_id","VertexLabel:"+id).next()
   v = g.V(id).next()
   v = g.V().hasId(id).next()
   v = g.V().hasId("VertexLabel:"+id).next()
   v = g.V("VertexLabel:"+id).next()

Edit

After some investigation I found that for a vertex v, v.id() returns a LinkedHashMap:

Vertex v = gT.next();
Object id = v.id();
System.out.println(id);
System.out.println(id.getClass());
System.out.println(g.V().hasId(id).next());
System.out.println(g.V(id).next());

The above prints:

{~label=User, community_id=1488246528, member_id=512}
class java.util.LinkedHashMap
v[{~label=User, community_id=1488246528, member_id=512}]
v[{~label=User, community_id=1488246528, member_id=512}]

There should be a more concise way ... any help is appreciated :)

Upvotes: 2

Views: 816

Answers (2)

Michail Michailidis
Michail Michailidis

Reputation: 12171

Actually I found it:

ids can be written in this String form: "vertexLabel:community_id:member_id"

So for the example above id="User:1488246528:512":

v = g.V().hasId("User:1488246528:512").next()
v = g.V("User:1488246528:512").next()

returns the specific Vertex

Till now I don't know of a good way how to print concisely the id (as a string) of a Vertex so it can be used in V() or in hasId() .. what I currently do is:

LinkedHashMap id = ((LinkedHashMap)v.id());
String idStr = v.label()+":"+id.get("community_id")+":"+id.get("member_id");

Upvotes: 2

jlacefie
jlacefie

Reputation: 614

Michail, you can also supply your own ids to help simplify this item. There are trade offs in doing so, but there are also advantages. Please see here for more details - http://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createCustVertexId.html?hl=custom%2Cid

Upvotes: 0

Related Questions