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

孤街浪徒 提交于 2020-01-23 13:33:27

问题


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 :)


回答1:


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");



回答2:


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



来源:https://stackoverflow.com/questions/41231293/how-to-query-by-vertex-id-in-datastax-dse-5-0-graph-in-a-concise-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!