You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Gremlin查找所有拥有多属性的图顶点?

查询拥有多属性的顶点方法

场景示例

先创建两个测试顶点:

g.addV('set-test').
    property('mySet','one').
    property(set_, 'mySet','two').
    property(id_,'set-test1').next()

g.addV('set-test2').
        property('mySet','three').next()

执行以下查询可查看顶点属性:

g.V().hasLabel("set-test").valueMap().toList()

返回结果:

[{'mySet': ['one', 'two']}]

以及:

g.V().hasLabel("set-test2").valueMap().toList()

返回结果:

[{'mySet': ['three']}]

需求:查询所有拥有多属性的顶点(如上述场景中标签为set-test的顶点)。

解决方案

针对特定属性筛选

如果只需要检查某个特定属性(比如mySet)是否存在多个值,可使用以下查询:

g.V().where(values('mySet').count(local).is(gt(1)))

该语句通过count(local)统计单个顶点的mySet属性值数量,筛选出数量大于1的顶点。

检查所有属性(不限定属性名)

如果要找出任意属性拥有多个值的顶点,可使用分组统计的方式:

g.V().where(properties().groupCount().select(values).unfold().is(gt(1)))

这个查询会先获取顶点的所有属性,按属性名分组后统计每组的数量,只要存在某组数量大于1,就返回该顶点。

内容的提问来源于stack exchange,提问作者Ste fan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 12:52:41