-1

When using gremlin console to connect gremlin server

run gremlin> graph=ConfiguredGraphFactory.open('test');
mgmt=graph.openManagement();mgmt.getVertexLabels()

will return:

==>person
==>animal

but when using the same gremlin sentence in java language to query vertex label it return:

{result{object=v[525] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex},
result{object=v[2061] class=org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex}}

i want to get the label name in java,how to do

Bharata
  • 13,509
  • 6
  • 36
  • 50
l.chq
  • 13
  • 2

1 Answers1

2

The getVertexLabels() method returns a VertexLabelobject. That object implements TinkerPop's Vertex interface. When you execute that code in Java (presumably via a remote script in JanusGraph Server - i.e. Gremlin Server) the VertexLabel is coerced to a DetachedVertex - that's just how Gremlin Server treats all Vertex instances. I would guess that if you wanted the actual "label" you would simply issue your script to get the label itself:

mgmt.getVertexLabels().collect{it.name()}

That will coerce the vertex labels to strings and then you'll get what you want.

stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • i have tried the gremlin sentence you offered,but cannot get the vertexlabel as 'person' or 'animal', – l.chq Jul 23 '18 at 01:15
  • just get the label 'vertex',it is not what i want to get – l.chq Jul 23 '18 at 01:17
  • hmm - perhaps use `toString()` rather than `label()` (that's what the console would do) – stephen mallette Jul 23 '18 at 11:11
  • my java code is: List result = client.submit("graph=ConfiguredGraphFactory.open('test'); mgmt=graph.openManagement();mgmt.getVertexLabels()").stream().map(r->r.toString()).collect(Collectors.toList()); it also returns the DetachedVertex @stephen mallette – l.chq Aug 15 '18 at 07:26
  • it works! this method got the actual label of vertex! – l.chq Aug 16 '18 at 09:12