Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gremlin groupCount() return only gt 2

I have the following Gremlin traversal, running on Azure CosmosDB, and I only want to return URLs with a count greater than 1. I'm not sure how to limit the return from the groupCount().

g.V().hasLabel('article').values('url').groupCount()

like image 897
David Torres Avatar asked Dec 18 '25 23:12

David Torres


2 Answers

Here's an example from the modern toy graph:

gremlin> g = TinkerFactory.createModern().traversal()
==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
gremlin> g.V().hasLabel('software').in().
......1>   groupCount().
......2>     by('name').
......3>   unfold().
......4>   filter(select(values).unfold().is(gt(1)))
==>josh=2

So you do the groupCount() and then unfold() the resulting Map then filter() the individual values from the Map.

In your case you would probably have something like:

g.V().hasLabel('article').
  groupCount()
    by('url').
  unfold().
  filter(select(values).unfold().is(gt(1)))
like image 96
stephen mallette Avatar answered Dec 20 '25 15:12

stephen mallette


Per my comment on the answer from Stephen Mallette, Azure CosmosDB Graph https://learn.microsoft.com/en-us/azure/cosmos-db/gremlin-support doesn't support the filter step so I used the where step to achieve the desired results.

g.V().hasLabel('article').groupCount().by('url').unfold().where(select(values).is(gt(1)))

like image 39
David Torres Avatar answered Dec 20 '25 15:12

David Torres



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!