3

I have following structure in a Janusgraph database:

gremlin> continent = g.addV("continent").property("name", "Europe").next()
gremlin> country = g.addV("country").property("name", "France").next()
gremlin> region = g.addV("region").property("name", "Ile-de-France").next()
gremlin> departement = g.addV("departement").property("name", "Hauts-de-Seine").next()
gremlin> city = g.addV("city").property("name", "Saint-Cloud").next()
gremlin> g.V(continent).addE('is_part_of').to(country).iterate()
gremlin> g.V(country).addE('is_part_of').to(region).iterate()
gremlin> g.V(region).addE('is_part_of').to(departement).iterate()
gremlin> g.V(departement).addE('is_part_of').to(city).iterate()

I did to get the property name from all vertices from city to continent from the following query:

gremlin> g.V(city).emit().repeat(inE("is_part_of").outV().simplePath()).path().unfold().dedup().values("name")
==>Saint-Cloud
==>Hauts-de-Seine
==>Ile-de-France
==>France
==>Europe

But I would like to get also the id and the label of every returned vertex. I tried to use valueMap(true) instead of values("name") step to get all properties including id and label, but big part of vertices contain lot of properties which could be heavy in the level of performance. Is it possible to get those values from each vertex?

ibt23sec5
  • 369
  • 3
  • 13

1 Answers1

3

You could just do valueMap(true, 'name')

gremlin> g.V(city).emit().repeat(inE("is_part_of").outV().simplePath()).
......1>   path().
......2>   unfold().
......3>   dedup().
......4>   valueMap(true,'name')
==>[id:8,label:city,name:[Saint-Cloud]]
==>[id:13,label:is_part_of]
==>[id:6,label:departement,name:[Hauts-de-Seine]]
==>[id:12,label:is_part_of]
==>[id:4,label:region,name:[Ile-de-France]]
==>[id:11,label:is_part_of]
==>[id:2,label:country,name:[France]]
==>[id:10,label:is_part_of]
==>[id:0,label:continent,name:[Europe]]
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thank you @stephen. I just added the `select()` step to get only vertex properties since my initial query returns also the edge metadata: `g.V(city).emit().repeat(inE("is_part_of").outV().as("a").simplePath()).path().unfold().dedup().select("a").dedup().valueMap(true, 'name')` – ibt23sec5 Sep 24 '19 at 13:22
  • you shouldn't have to do that. just do `repeat(__.in('is_part_of')).simplePath())`rather than`inE().outV()`. – stephen mallette Sep 24 '19 at 13:24