Gremlin 将所有返回的边及其顶点分组

Gremlin group all returned edges with its vertices

我是 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())

但它 returns 此结构中每个评级的数据数组:

["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}}

我怎样才能做到这一点? 提前致谢。

您应该查看使用 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())