简体   繁体   English

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

[英]Gremlin group all returned edges with its vertices

I am a beginner in gremlin with Tinker pop.我是 Tinker pop 的小精灵初学者。 I have a graph where a cuisine has multiple inE("serves") from restaurants:我有一个图表,其中一个菜系有多个来自餐厅的inE("serves") 在此处输入图片说明

From these restaurants, I want only two restaurants which have location "Karachi".在这些餐厅中,我只想要两家位于“卡拉奇”的餐厅。 These are:这些是: 在此处输入图片说明 在此处输入图片说明

For this, I've written the query and it works fine:为此,我编写了查询并且它工作正常:

g.V(26).as("cui").inE("serves").outV().hasLabel("restaurant").has("location", "karachi").as("rest")

What I want is a gremlin query that gets the inE("reviews") of these restaurants and shape the data in this way.我想要的是一个 gremlin 查询,它获取这些餐厅的inE("reviews")并以这种方式塑造数据。

[
"restaurant" : // info related to restaurant,
"reviews": [{array of reviews}]
]

I've tried this script:我试过这个脚本:

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

But it returns an array of data for every rating in this structure:但它为这个结构中的每个评分返回一个数据数组:

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

How can I achieve this?我怎样才能做到这一点? Thanks in advance.提前致谢。

You should look at using the project() step (documentation here ) to get this sort of information.您应该查看使用project()步骤( 此处的文档)来获取此类信息。 Without the steps to reproduce your graph, it is hard to give you the exact query, but it should look similar to the query below:如果没有重现图形的步骤,很难为您提供准确的查询,但它应该类似于以下查询:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM