Java 如何利用gremlin和janusgraph获得顶点和边的组合属性
我在spring boot应用程序中使用JanusGraph作为图形数据库,我想形成一个gremlin查询来检索出边界及其关联顶点的属性。我还希望在属性中包含标记(id、标签等) 我想要这个gremlin查询的java实现。Java 如何利用gremlin和janusgraph获得顶点和边的组合属性,java,graph-databases,gremlin,janusgraph,Java,Graph Databases,Gremlin,Janusgraph,我在spring boot应用程序中使用JanusGraph作为图形数据库,我想形成一个gremlin查询来检索出边界及其关联顶点的属性。我还希望在属性中包含标记(id、标签等) 我想要这个gremlin查询的java实现。List propertyList=g.V(“V\u ID”)//获取顶点 List<Map<String, Object>> propertyList = g.V("V_ID") // Get the vertex .outE().hasLabe
List propertyList=g.V(“V\u ID”)//获取顶点
List<Map<String, Object>> propertyList = g.V("V_ID") // Get the vertex
.outE().hasLabel("OUT_EDGE").as("E") // Get the outgoing edge as E
.inV().as("V") // Get the vertex(pointed by E) as V
.select("E", "V") // Select Edge E and Vertex V
.by(__.valueMap().with(WithOptions.tokens).unfold() // Get value map including tokens
.group().by(Column.keys).by(__.select(Column.values).unfold())) // Form key value pairs
.toList(); // Return the list of properties
.outE().hasLabel(“OUT_EDGE”).as(“E”)//将传出边获取为E
.inV().as(“V”)//获取顶点(由E指向)作为V
.选择(“E”、“V”)//选择边E和顶点V
.by(_u.valueMap().with(WithOptions.tokens).unfold()//获取包含标记的值映射
.group().by(Column.keys).by(_uu.select(Column.values.unfold())//形成键值对
.toList();//返回属性列表
注:根据替换示例字符串(“V_ID”、“OUT_EDGE”)标记
您的实现
上面的查询将返回java map中边及其关联顶点的所有属性。属性映射还将包含标记(即id、标签)
在这里,我必须分组并展开valueMap()
,因为默认情况下valueMap()
将值字段包装在数组中,我不希望出现这种行为,因为我的所有属性都具有单个值,所以获取包含单个值的列表没有意义
现在,所有边和关联的顶点属性都已合并,并可与
propertyList
一起使用。我认为使用project()
(如果可能,elementMap()
)可以更好地编写查询:
g.V("V_ID").outE('OUT_EDGE').
project('eData','vData').
by(elementMap())