用于标识具有边的标签"A"的顶点的查询 标签"B"的多个顶点

  • 本文关键字:顶点 标签 查询 标识 用于 gremlin
  • 更新时间 :
  • 英文 :


我有一个带有标签"的顶点的图;组织;其中边缘到标签"的顶点;social_account";。在这种一对多关系中,组织顶点在每个不同的社交平台上应该只有一个social_account顶点。也就是说,一个组织可以具有"边缘";Twitter";social_account顶点;中等;social_account顶点和";Instagram";social_account顶点,但它不应该具有到多个"的边;Twitter";social_account顶点,如图所示:

玩具数据图

我想要一个查询,它标识:

给定社交平台的
  1. 组织具有多个social_account顶点
  2. 应根据updated_at值删除的关联social_account顶点的ID

我有以下查询,它返回组织ID和组织顶点有边的social_account顶点的关联ID。

g.V().hasLabel("organization").as("org", "social_ids").select("org", "social_ids").by(id).by(out().hasLabel('social_account').id().fold())

给定一个输入";Twitter";我想看到一些类似于上面玩具数据的东西:

[org: Org-2, to_drop: [Twitter-39]]

以及对应于social_account"的一般输入的类似输出;"社交";所有物

我对Gremlin还比较陌生,所以如果能有效地将这些结果过滤成所需的输出,我将不胜感激。

当您提供构建图的遍历时,它会有很大帮助,这样我们就可以给您一个经过测试的答案。

g.addV('Organization').property(id, 'Org-1').as('org1').
addV('social_account').property(id, 'Twitter-01').property('social', 'Twitter').property('updated_at', 1234).as('twitter01').
addE('has_social_account').from('org1').to('twitter01').
addV('social_account').property(id, 'Medium-34').property('social', 'Medium').property('updated_at', 1345).as('medium34').
addE('has_social_account').from('org1').to('medium34').
addV('social_account').property(id, 'Insta-55').property('social', 'Instagram').property('updated_at', 4567).as('insta55').
addE('has_social_account').from('org1').to('insta55').
addV('Organization').property(id, 'Org-2').as('org2').
addV('social_account').property(id, 'Twitter-39').property('social', 'Twitter').property('updated_at', 1111).as('twitter39').
addE('has_social_account').from('org2').to('twitter39').
addV('social_account').property(id, 'Twitter-60').property('social', 'Twitter').property('updated_at', 2345).as('twitter60').
addE('has_social_account').from('org2').to('twitter60').
addV('social_account').property(id, 'Insta-19').property('social', 'Instagram').property('updated_at', 4567).as('insta19').
addE('has_social_account').from('org2').to('insta19')

下面是遍历,获取拥有多个Twitter帐户的组织以及需要删除的Twitter帐户的ID。

g.V().hasLabel('Organization').where(out('has_social_account').has('social', 'Twitter').count().is(gt(1))).
project('org', 'to_drop').
by(id).
by(out('has_social_account').has('social', 'Twitter').
order().by('updated_at', desc).
range(1, -1).id().fold())

where步骤按拥有多个Twitter帐户的组织进行筛选。project步骤获取需要删除的这些组织及其Twitter帐户的ID。

为了获得需要删除的推特账户,第二个by调制器中的嵌套遍历获得与组织相关联的推特账号,基于"0"的值对其进行排序;updated_ at";(下降(。然后使用range步骤跳过不需要删除的第一个Twitter帐户。

最新更新