What is the right way to find an edge between two vertices?
graph, graph-databases, neo4j, tinkerpop, titan
Solution
gremlin> g.v(1).bothE.as('x').bothV.retain([g.v(3)]).back('x')
Problem
Using tinkerpop blueprints API, what is the best way to find if an edge exists between two vertices? I would like to avoid `vertex.getEdges()` and iterate until find the right one. E.g.: Check if `v1` is friend of `v2` ``` Vertex v1 = g.addVertex(null); Vertex v2 = g.addVertex(null); Edge edge = g.addEdge(null, v1, v2, "friends"); Edge edge = g.addEdge(null, v1, v2, "follows"); // Node with lots of edges - Supernode - problem? List<Edge> edges = new ArrayList<Edge>(); for(Edge edge : g.getVertex(v1.getId()).getEdges(Direction.OUT, "friends")){ if(edge.getVertex(Direction.IN).getId().equals(v2.getId()){ edges.add(edge); } } ``` Should I use Vertex Query? Via gremlin I could do: ``` g.v(v1.getID()).outE("friends").inV.filter{it.id == v2.getID} ``` Neo4j way: ``` IndexHits<Relationship> relationships = relationshipIndex().get("type", edgeType, node1, node2); ``` Thanks for the help! I am still new to this.