Gremlin 组所有返回的边及其顶点
Posted
技术标签:
【中文标题】Gremlin 组所有返回的边及其顶点【英文标题】:Gremlin group all returned edges with its vertices 【发布时间】:2021-12-27 19:52:52 【问题描述】:我是使用 Tinker pop 的 gremlin 初学者。我有一个图表,其中一个美食有多个来自餐厅的inE("serves")
:
从这些餐厅中,我只想要两家位置为“卡拉奇”的餐厅。 这些是:
为此,我已经编写了查询并且运行良好:
g.V(26).as("cui").inE("serves").outV().hasLabel("restaurant").has("location", "karachi").as("rest")
我想要的是一个 gremlin 查询,它获取这些餐馆的 inE("reviews")
并以这种方式塑造数据。
[
"restaurant" : // info related to restaurant,
"reviews": [array of reviews]
]
我试过这个脚本:
g.V(26).as("cui").inE("serves").outV().hasLabel("restaurant").has("location", "karachi").as("rest").where(__.inE("review").has("value",is(gte(2)))).inE("review").order().by("value", desc).as("rev").select("rest","rev").by(elementMap())
但它会为这个结构中的每个评分返回一个数据数组:
["rest": , "rating:" ],
["rest": , "rating:" ],
==>rest=id=54, label=restaurant, name=restaurant5, location=karachi, rev=id=67, label=review, IN=id=54, label=restaurant, OUT=id=9, label=user, upvotes=3, rated_at=Tue Nov 16 22:13:58 PKT 2021, downvotes=1, value=12
==>rest=id=60, label=restaurant, name=restaurant7, location=karachi, rev=id=69, label=review, IN=id=60, label=restaurant, OUT=id=6, label=user, upvotes=4, rated_at=Tue Nov 16 22:16:45 PKT 2021, downvotes=3, value=5
==>rest=id=60, label=restaurant, name=restaurant7, location=karachi, rev=id=71, label=review, IN=id=60, label=restaurant, OUT=id=9, label=user, upvotes=1, rated_at=Tue Nov 16 22:16:45 PKT 2021, downvotes=5, value=5
==>rest=id=12, label=restaurant, name=restaurant1, location=karachi, rev=id=41, label=review, IN=id=12, label=restaurant, OUT=id=0, label=user, upvotes=8, rated_at=Tue Nov 16 21:49:07 PKT 2021, downvotes=4, value=4
==>rest=id=54, label=restaurant, name=restaurant5, location=karachi, rev=id=65, label=review, IN=id=54, label=restaurant, OUT=id=6, label=user, upvotes=4, rated_at=Tue Nov 16 22:12:57 PKT 2021, downvotes=1, value=4
==>rest=id=12, label=restaurant, name=restaurant1, location=karachi, rev=id=40, label=review, IN=id=12, label=restaurant, OUT=id=3, label=user, upvotes=8, rated_at=Tue Nov 16 21:49:07 PKT 2021, downvotes=4, value=3.7
==>rest=id=60, label=restaurant, name=restaurant7, location=karachi, rev=id=70, label=review, IN=id=60, label=restaurant, OUT=id=0, label=user, upvotes=5, rated_at=Tue Nov 16 22:16:45 PKT 2021, downvotes=2, value=3
==>rest=id=54, label=restaurant, name=restaurant5, location=karachi, rev=id=68, label=review, IN=id=54, label=restaurant, OUT=id=3, label=user, upvotes=2, rated_at=Tue Nov 16 22:14:21 PKT 2021, downvotes=9, value=3
==>rest=id=60, label=restaurant, name=restaurant7, location=karachi, rev=id=72, label=review, IN=id=60, label=restaurant, OUT=id=3, label=user, upvotes=5, rated_at=Tue Nov 16 22:16:46 PKT 2021, downvotes=1, value=2
==>rest=id=54, label=restaurant, name=restaurant5, location=karachi, rev=id=66, label=review, IN=id=54, label=restaurant, OUT=id=0, label=user, upvotes=4.7, rated_at=Tue Nov 16 22:13:32 PKT 2021, downvotes=3, value=2
我怎样才能做到这一点? 提前致谢。
【问题讨论】:
【参考方案1】:您应该考虑使用project()
步骤(文档here)来获取此类信息。如果没有重现图表的步骤,很难为您提供准确的查询,但它应该类似于下面的查询:
g.V(26).as("cui").
inE("serves").
outV().
hasLabel("restaurant").
has("location", "karachi").
project('restaurant', 'reviews').
by(elementMap()).
by(
inE("review").
has('value', gte(2)).
order().by("value", desc).
fold())
【讨论】:
非常感谢!!这正是我想要的!以上是关于Gremlin 组所有返回的边及其顶点的主要内容,如果未能解决你的问题,请参考以下文章