Search code examples
graph-databasesgremlintinkerpop3janusgraph

I'd like to return all the vertex and all the path for the vertexes which we returned


My question is that I want to return all the vertexes. And get all paths between all returned vertexes.

For example I will get all the tags which is person. And I also want to get all the paths between the vertexes.

vertexes : g.V().has('tag','person') How can we get the net path?


Solution

  • g.V().has('tag', 'person') is not going to return any paths, since this query is meant to only return a list of vertices.

    I'll assume from your comment that you want all paths between all such vertices, then the following query should be useful:

    g.V().has('tag', 'person').bothE().otherV().path()
    

    It might be useful to add a dedup() step on destination vertices, so you don't get duplicate paths:

    g.V().has('tag', 'person').bothE().otherV().dedup().path()
    

    For a more sophisticated output of path(), you can experiment with the Gremlin console and the toy graph. The following apply different by() modulators for source vertex, traversed edge, and destination vertex (respectively):

    gremlin> graph = TinkerFactory.createModern()
    gremlin> g = graph.traversal(standard())
    ==>graphtraversalsource[tinkergraph[vertices:6 edges:6], standard]
    gremlin> g.V().bothE().otherV().dedup().path().by(id).by(label).by(id)
    ==>[1, created, 3]
    ==>[1, knows, 2]
    ==>[1, knows, 4]
    ==>[2, knows, 1]
    ==>[3, created, 6]
    ==>[4, created, 5]
    

    Reference: