获取沿路径具有特定 属性、标签和 ID 的所有顶点
Get all vertices with a specific property, label and id along the path
我在 Janusgraph 数据库中有以下结构:
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()
我确实从 city 到 continent 的所有顶点得到了 属性 name
从以下查询:
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
但我还想获得每个返回顶点的 id
和 label
。
我尝试使用 valueMap(true)
而不是 values("name")
步骤来获取所有属性,包括 id
和 label
,但是大部分顶点包含很多属性,这些属性在关卡中可能很重性能。
是否可以从每个顶点获取这些值?
你可以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]]
我在 Janusgraph 数据库中有以下结构:
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()
我确实从 city 到 continent 的所有顶点得到了 属性 name
从以下查询:
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
但我还想获得每个返回顶点的 id
和 label
。
我尝试使用 valueMap(true)
而不是 values("name")
步骤来获取所有属性,包括 id
和 label
,但是大部分顶点包含很多属性,这些属性在关卡中可能很重性能。
是否可以从每个顶点获取这些值?
你可以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]]