user2524707 - 9 months ago 51

Java Question

I am trying to retrieve all edges which connect any of the nodes in set A and one of the nodes in set B.

Current approach:

`ArrayList<Vertex> nodeStartList = getVertexList(relationshipStorage.getStartNode(), g, snapshotId);`

ArrayList<Vertex> nodeEndList = getVertexList(relationshipStorage.getEndNode(), g, snapshotId);

The vertex lists are correctly filled (Already checked that)

`GraphTraversal<Vertex, Edge> tempOutput = g.V(nodeStartList.toArray()).bothE().where(__.is(P.within(nodeEndList.toArray()))).hasLabel(relationshipStorage.getId());`

But I always retrieve an empty list from output.

And I'm sure I have edges matching my query.

Answer Source

Here is something that works:

```
gremlin> graph = TinkerGraph.open();
==>tinkergraph[vertices:0 edges:0]
gremlin> v1 = graph.addVertex();
gremlin> v2 = graph.addVertex();
gremlin> v3 = graph.addVertex();
gremlin> v4 = graph.addVertex();
gremlin> v5 = graph.addVertex();
gremlin> v6 = graph.addVertex();
gremlin> v1.addEdge("edgeLabel", v4);
gremlin> v2.addEdge("edgeLabel", v5);
gremlin> v3.addEdge("edgeLabel", v6);
```

The above creates 6 vertices with 3 edges between them. I can then find those edges with:

```
gremlin> graph.traversal().V(v1, v2, v3).bothE().filter(otherV().is(within(v4, v5, v6)))
==>e[6][0-edgeLabel->3]
==>e[7][1-edgeLabel->4]
==>e[8][2-edgeLabel->5]
```