【问题标题】:how to query by vertex id in Datastax DSE 5.0 Graph in a concise way?如何以简洁的方式在Datastax DSE 5.0 Graph中按顶点ID查询?
【发布时间】:2017-05-05 00:26:42
【问题描述】:

似乎顶点的唯一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}]

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

【问题讨论】:

    标签: datastax gremlin datastax-enterprise-graph


    【解决方案1】:

    其实我找到了:

    id可以写成这样的String形式:"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");
    

    【讨论】:

      【解决方案2】:

      Michail,您也可以提供自己的 ID 来帮助简化此项目。这样做有取舍,但也有好处。详情请看这里 - http://docs.datastax.com/en/latest-dse/datastax_enterprise/graph/using/createCustVertexId.html?hl=custom%2Cid

      【讨论】:

      • 是的,我知道它存在,但除非它是 UUID,否则我认为我不知道另一个 id 可能是什么......
      猜你喜欢
      • 2017-08-29
      • 2017-05-05
      • 1970-01-01
      • 2017-05-05
      • 2017-05-06
      • 2023-04-06
      • 2016-12-29
      • 1970-01-01
      • 2023-03-28
      相关资源
      最近更新 更多