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()
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)))
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)))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With