Gremlin:GroupBy顶点,有计数> 1

时间:2015-05-11 09:39:17

标签: graph graph-databases titan gremlin

我正在使用TITAN 0.4和gremlin进行遍历。 我的要求是在图中识别重复的顶点,并合并它们。 有>图中15个顶点。

gremlin> g.V.has('domain').groupBy{it.domain}{it.id}.cap

==>{google.com=[4], yahoo.com=[16, 24, 20]}

我能够对顶点进行分组,但我只需要那些不止一次存在的域(顶点)。

在上面的示例中,我只需要返回==>{yahoo.com=[16, 24, 20]} 关键"域"被索引,如果这有任何区别。

请在这里帮助我

2 个答案:

答案 0 :(得分:2)

考虑使用groupCount而不是groupBy来保存在您收集的列表中计算ID的步骤:

g.V.has('domain').groupCount(it.domain}.cap.next().findAll{it.value>1}

我认为这在更大的遍历上更便宜,因为你只是维护一个计数器而不是标识符列表。

答案 1 :(得分:0)

老问题,但是你在下面尝试强制索引吗?

g.V.hasNot('domain', null).groupBy{it.domain}{it.id}.cap