Pradatta
Pradatta

Reputation: 3360

How can I search for a vertex and create edge in a single query?

I am using gremlin query to search for vertices from a given vertex.

v.both("edgeLabel").has("propertykey", "27826345");

This query is returning a bunch of vertices. Now I am creating edges from 'v' to all those returned vertices by simple iterator.

Now my question is:
Is there any process/query style available through which I can search for those vertices and create edges in the same query ?

I have already tried this query:

 v.both('edgeLabel').has('propertykey','27826345').gather(){g.addEdge(v,it,'TEST_LABEL')}

But I'm getting error :

No signature of method: groovy.lang.MissingMethodException.addEdge()

I am currently using Gremlin-Groovy ScriptEngine to execute my query from a Java class.

Thank you in Advance.

Upvotes: 0

Views: 974

Answers (2)

Marko A. Rodriguez
Marko A. Rodriguez

Reputation: 1702

In Gremlin 2.3.0, there are three new steps:

 linkIn
 linkOut
 linkBoth

Please see GremlinDocs (http://gremlindocs.com) for more information on how to use them.

http://gremlindocs.com/#transform/linkboth-in-out

Note that these pipes yield a sideEffect (the edge generated) so you can cap the pipe if you need to get the edge.

Upvotes: 1

zmaril
zmaril

Reputation: 296

You probably need to provide an id to addEdge. Here are the javadocs.

v.both('edgeLabel').has('propertykey','27826345').gather(){g.addEdge(1,v,it,'TEST_LABEL')}

Upvotes: 0

Related Questions