如何通过Datastax DSE 5.0 Graph中的顶点id以简洁的方式进行查询?

时间:2016-12-19 21:27:48

标签: datastax gremlin datastax-enterprise-graph

似乎顶点的唯一ID是DSE Graph中的community_id。

我发现这有效(id很长):

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

这些都不起作用:

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

修改

经过一番调查,我发现对于顶点v,v.id()返回一个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());

以上版画:

{~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}]

应该有一个更简洁的方式...... 任何帮助表示赞赏:)

2 个答案:

答案 0 :(得分:2)

其实我找到了它:

ids可以用这种字符串形式写成:"vertexLabel:community_id:member_id"

所以对于上面的示例id="User:1488246528:512"

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

返回特定的顶点

到目前为止,我还不知道如何简洁地打印Vertex的id(作为字符串),以便在V()或hasId()中使用..我目前所做的是:

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

答案 1 :(得分:0)

Michail,您也可以提供自己的ID来帮助简化此项目。这样做有折衷,但也有优势。有关详细信息,请参阅此处 - http://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createCustVertexId.html?hl=custom%2Cid