Reputation: 33
I want to get the list of all the labels available in the graph, but I am unaware of the schema. Is there any way to find out the list of all the labels?
I have tried the following:
g.V().Label().values()
g.V().hasLabel().values()
but they are not working.
Upvotes: 3
Views: 2183
Reputation: 83
In Scala, if all you have is a GraphTraversalSource from a JanusGraph, you can do:
import org.janusgraph.core.JanusGraph
val graph: JanusGraph = g.getGraph.asInstanceOf[JanusGraph]
val mgmt: JanusGraphManagement = graph.openManagement()
and then from there get your iterable of vertex labels:
val vLabels: Iterable[VertexLabel] = mgmt.getVertexLabels.asScala
(The .asScala only works if you have imported gremlin-scala; otherwise you can omit it and you'll get a Java iterator.)
Upvotes: 0
Reputation: 46226
In Gremlin you would do:
g.V().label().dedup()
but that would require a scan of all vertices in the graph which would be expensive. JanusGraph has schema you can query with the JanusGraphManagement
class.
JanusGraphManagement mgmt = graph.openManagement();
Iterable<VertexLabel> labels = mgmt.getVertexLabels();
Upvotes: 7