4

consider I have around 5 vertices from v1 to v5. and having the edges between them. the structure is below.

v1->v2
v1->v3
v4->v2
v2->v1
v2->v3
v3->v5
v5->v1

Now I want to write a gremlin query to display the vertices which is having outgoing edges is 2.

for example v1 is having 2 outgoing edges to v2 and v3 so here the query should display v1,v2,v3

Arundhathi D
  • 304
  • 6
  • 22

1 Answers1

6

There's a few way to do this. You can just get all of the nodes you want without any information about where they come from

g.V().where(out().count().is(2)).union(identity(), out())

which would return

==>v[1]
==>v[2]
==>v[3]

or you can get all of the paths to the outgoing edges. This will let you show which have the out count of 2.

g.V().where(out().count().is(2)).out().path()

which would give you

==>[v[1], v[2]]
==>[v[1], v[3]]

Keep in mind, this is going to get much slower as your graph grows since it will be accessing every vertex in your graph.

For future reference, you should show examples of what you've tried so far, and desired output. It makes it easier to help.

pantalohnes
  • 961
  • 5
  • 12
  • Thanks for replying my questions. I am searching for gremlin documentation or book. I am not getting proper one. Could you please refer me a good document or book for gremlin. – Arundhathi D May 30 '17 at 06:32
  • @ArundhathiD http://tinkerpop.apache.org/docs/current/reference/ is the most current, but Titan is quite a few versions back since it is no longer maintained.http://tinkerpop.apache.org/docs/3.0.1-SNAPSHOT/ is the version Titan is on I believe. I'd recommend checking out http://janusgraph.org which picked up where Titan left off and is using a much more current Tinkerpop. The current release is backward compatible with Titan. http://sql2gremlin.com is a pretty good tutorial if you're already familiar with SQL – pantalohnes May 30 '17 at 11:19
  • I have a graph of 6 nodes in which around 4 nodes have multiple edges between them . Say my graph nodes are a,b,c,d,e,f and edges are a-b,a-b,a-b,c-d,b-d,e-f,e-f I want a query that will return vertices a,b along with the multiple edges a-b,a-b similarly it should also return e,f with edges e-f,e-f – Arundhathi D Jun 01 '17 at 09:47
  • could you please help me to find out query for this. – Arundhathi D Jun 01 '17 at 09:47
  • Please create a separate question. You should include queries you've already tried as well. – pantalohnes Jun 01 '17 at 10:34
  • The question is already present. below is my question name gremlin query to get multiple edges between two particular vertices. – Arundhathi D Jun 01 '17 at 10:41