如何使用gremlin和janusgraph获得合并的顶点和边属性

问题描述 投票:0回答:1

我在春季启动应用程序中将JanusGraph用作图形数据库,并且我想形成一个gremlin查询以检索传出Edge及其关联的Vertex的属性。我还希望将标记(id,标签等)包含在属性中。

我想要此gremlin查询的Java实现。

java graph-databases gremlin janusgraph
1个回答
0
投票
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

注意:请按照以下说明替换示例字符串(“ V_ID”,“ OUT_EDGE”)标记您的实施

上面的查询将返回java映射中边的所有属性及其关联的顶点。属性映射还将包含令牌(即ID,标签)。

在这里,我不得不对valueMap()进行分组和展开,因为默认情况下valueMap()将Value字段包装在数组内,并且我不希望出现这种情况,因为我拥有所有具有单个值的属性,因此毫无意义一个包含单个值的列表。

您现在合并了所有的边和关联的顶点属性,并可以在propertyList中使用。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.