计算
弹性云服务器 ECS
Flexus云服务
裸金属服务器 BMS
弹性伸缩 AS
镜像服务 IMS
专属主机 DeH
函数工作流 FunctionGraph
云手机服务器 CPH
Huawei Cloud EulerOS
网络
虚拟私有云 VPC
弹性公网IP EIP
虚拟专用网络 VPN
弹性负载均衡 ELB
NAT网关 NAT
云专线 DC
VPC终端节点 VPCEP
云连接 CC
企业路由器 ER
企业交换机 ESW
全球加速 GA
安全与合规
安全技术与应用
Web应用防火墙 WAF
企业主机安全 HSS
云防火墙 CFW
安全云脑 SecMaster
DDoS防护 AAD
数据加密服务 DEW
数据库安全服务 DBSS
云堡垒机 CBH
数据安全中心 DSC
云证书管理服务 CCM
边缘安全 EdgeSec
CDN与智能边缘
内容分发网络 CDN
CloudPond云服务
智能边缘云 IEC
迁移
主机迁移服务 SMS
对象存储迁移服务 OMS
云数据迁移 CDM
迁移中心 MGC
大数据
MapReduce服务 MRS
数据湖探索 DLI
表格存储服务 CloudTable
云搜索服务 CSS
数据接入服务 DIS
数据仓库服务 GaussDB(DWS)
数据治理中心 DataArts Studio
数据可视化 DLV
数据湖工厂 DLF
湖仓构建 LakeFormation
企业应用
云桌面 Workspace
应用与数据集成平台 ROMA Connect
云解析服务 DNS
专属云
专属计算集群 DCC
IoT物联网
IoT物联网
设备接入 IoTDA
智能边缘平台 IEF
用户服务
账号中心
费用中心
成本中心
资源中心
企业管理
工单管理
国际站常见问题
ICP备案
我的凭证
支持计划
客户运营能力
合作伙伴支持计划
专业服务
区块链
区块链服务 BCS
Web3节点引擎服务 NES
解决方案
SAP
高性能计算 HPC
视频
视频直播 Live
视频点播 VOD
媒体处理 MPC
实时音视频 SparkRTC
数字内容生产线 MetaStudio
存储
对象存储服务 OBS
云硬盘 EVS
云备份 CBR
存储容灾服务 SDRS
高性能弹性文件服务 SFS Turbo
弹性文件服务 SFS
云硬盘备份 VBS
云服务器备份 CSBS
数据快递服务 DES
专属分布式存储服务 DSS
容器
云容器引擎 CCE
容器镜像服务 SWR
应用服务网格 ASM
华为云UCS
云容器实例 CCI
管理与监管
云监控服务 CES
统一身份认证服务 IAM
资源编排服务 RFS
云审计服务 CTS
标签管理服务 TMS
云日志服务 LTS
配置审计 Config
资源访问管理 RAM
消息通知服务 SMN
应用运维管理 AOM
应用性能管理 APM
组织 Organizations
优化顾问 OA
IAM 身份中心
云运维中心 COC
资源治理中心 RGC
应用身份管理服务 OneAccess
数据库
云数据库 RDS
文档数据库服务 DDS
数据管理服务 DAS
数据复制服务 DRS
云数据库 GeminiDB
云数据库 GaussDB
分布式数据库中间件 DDM
数据库和应用迁移 UGO
云数据库 TaurusDB
人工智能
人脸识别服务 FRS
图引擎服务 GES
图像识别 Image
内容审核 Moderation
文字识别 OCR
AI开发平台ModelArts
图像搜索 ImageSearch
对话机器人服务 CBS
华为HiLens
视频智能分析服务 VIAS
语音交互服务 SIS
应用中间件
分布式缓存服务 DCS
API网关 APIG
微服务引擎 CSE
分布式消息服务Kafka版
分布式消息服务RabbitMQ版
分布式消息服务RocketMQ版
多活高可用服务 MAS
事件网格 EG
企业协同
华为云会议 Meeting
云通信
消息&短信 MSGSMS
云生态
合作伙伴中心
云商店
开发者工具
SDK开发指南
API签名指南
Terraform
华为云命令行工具服务 KooCLI
其他
产品价格详情
系统权限
管理控制台
客户关联华为云合作伙伴须知
消息中心
公共问题
开发与运维
应用管理与运维平台 ServiceStage
软件开发生产线 CodeArts
需求管理 CodeArts Req
部署 CodeArts Deploy
性能测试 CodeArts PerfTest
编译构建 CodeArts Build
流水线 CodeArts Pipeline
制品仓库 CodeArts Artifact
测试计划 CodeArts TestPlan
代码检查 CodeArts Check
代码托管 CodeArts Repo
云应用引擎 CAE
开天aPaaS
云消息服务 KooMessage
云手机服务 KooPhone
云空间服务 KooDrive

支持的表达式,函数及过程

更新时间:2025-03-05 GMT+08:00

表达式

Cypher查询支持多种的表达式,可以组合成丰富的过滤条件,目前支持的表达式如下:

运算类型

表达式

举例&备注

逻辑运算

and

match (n:user) where n.age='Under 18' and n.gender='F' return n

or

match(n:user) where n.`Zip-code`='22181' or n.userid=6 return n

not

match(n:movie) where not n.genres contains 'Drama' return n

空值判断

is null

match (n) where n.userid is null return n

is not null

match (n) where n.userid is not null return n

比较运算

>,>=,<,<=,=,<>

match(n:user) where n.userid>=5 return n

算数运算

+,-,*,/,%,^

return (1+3)%3

字符串比较

starts with

match(n:movie) where n.genres starts with 'Comedy' return n

ends with

match(n:movie) where n.genres ends with 'Drama' return n

contains

match(n:movie) where n.genres contains 'Drama' return n

List相关运算

in

match(n:student) where 'math' in n.courses return n

[]运算符

match(n:user) return n[' userid']

with [1, 2, 3, 4] as list return list[0]

with [1, 2, 3, 4] as list return list[0..1]

match p=(n)-->(m) return [x in nodes(p) where x.gender='F'|id(x)]

日期表达式

.year, .month, .day, .hour, .minute, .second, .dayOfWeek

可以获取一个具体日期的年月日信息:with '2000-12-27 23:44:41' as strVal with datetime(strVal) as d2 return d2.year, d2.month, d2.day, d2.hour, d2.minute, d2.second,d2.dayOfWeek, d2.ordinalDay

说明:

Cypher查询的where子句暂不支持正则匹配。

函数

在分组聚集、点边操作时,cypher支持一系列的函数,目前支持的函数如下所示:

  1. 聚集函数

    函数名

    支持的最低版本

    释义

    举例

    count

    2.2.17

    求结果总数

    match (n) return count(*)

    match (n) return count(n.userid)

    collect

    2.2.17

    将结果聚集为列表

    match (n:movie) return n.genres, collect(n) as movieList

    sum

    2.3.3

    结果求和

    unwind [1, 2.0, 3] as p return sum(p)

    avg

    2.3.3

    结果求均值

    unwind [1, 2.0, 3] as p return avg(p)

    min

    2.3.3

    求最小值

    unwind [1, 2.0, 3] as p return min(p)

    max

    2.3.3

    求最大值

    unwind [1, 2.0, 3] as p return max(p)

  2. 普通函数

    根据入参不同,普通函数分为点边操作类、路径操作类、列表操作类、值操作类等几类函数。

    表1 点边操作类

    函数名

    支持的最低版本

    释义

    举例

    id

    2.2.16

    获取点的id

    match (n) return id(n)

    labels

    2.2.16

    获取点的label

    match (n) return labels(n)

    type

    2.2.16

    获取边的label

    match(n)-[r]->(m) return type(r)

    degree

    2.2.26

    获取点的度数

    match (n) where id=’Vivian’ return degree(n)

    inDegree

    2.2.26

    获取点的入度

    match (n) where id=’Vivian’ return inDegree(n)

    outDegree

    2.2.26

    获取点的出度

    match (n) where id=’Vivian’ return outDegree(n)

    startNode

    2.3.10

    获取边的入点

    match (n)-[r]->(m) return startNode(r)

    endNode

    2.3.10

    获取边的出点

    match (n)-[r]->(m) return endNode(r)

    表2 路径操作类函数(2.2.19)

    函数名

    支持的最低版本

    释义

    举例

    length

    2.2.19

    获取路径长度

    match p=(n)-[:friends*1..2]->(m) return length(p)

    表3 列表操作类函数

    函数名

    支持的最低版本

    释义

    举例

    head

    2.3.10

    获取列表的第一个元素

    with [1,2,3,4] as list return head(list)

    last

    2.3.10

    获取列表的最后一个元素

    with [1,2,3,4] as list return last(list)

    size

    2.3.10

    获取列表长度

    with [1,2,3,4] as list return size(list)

    range(2.3.10)

    2.3.10

    生成一个列表

    return range(1,5), range(1,5,2)

    表4 值操作类

    函数名

    支持的最低版本

    释义

    举例

    toString

    2.2.21

    将其他值类型转换为string

    match (n) where toString(labels(n)) contains 'movi' return n

    toUpper

    2.2.26

    将字符串变为大写

    match (n:movie) return toUpper(n.title)

    toLower

    2.2.26

    将字符串变为小写

    match (n:movie) return toLower(n.title)

    toInteger

    2.2.29

    将字符串转为int类型

    with '123' as p return toInteger(p)

    toLong

    2.2.29

    将字符串转为long类型

    with '123' as p return toLong(p)

    toFloat

    2.2.29

    将字符串转为float类型

    with '123.4' as p return toFloat(p)

    toDouble

    2.2.29

    将字符串转为double类型

    with '123.4' as p return toDouble(p)

    toBoolean

    2.2.29

    将字符串转为bool类型

    with 'true' as p return toBoolean(p)

    size

    2.2.29

    获取字符串的字符长度

    with 'GES' as p return size(p)

    subString

    2.3.10

    截取字符串的一部分

    return subString('abc', 1), subString('abcde', 1,2)

    coalesce

    2.3.10

    获取参数中第一个非null值。

    return coalesce(null, '123')

    trim

    2.3.11

    移除字符串两侧的空白字符。

    return trim(' hello ')

    lTrim

    2.3.11

    移除字符串左侧的空白字符。

    return lTrim(' hello')

    rTrim

    2.3.11

    移除字符串右侧的空白字符。

    return rTrim('hello ')

    reverse

    2.3.11

    翻转字符串

    return reverse('hello')

    left

    2.3.11

    从字符串左侧取若干个字符

    with 'hello' as p return left(p, 3)

    right

    2.3.11

    从字符串右侧取若干个字符

    with 'hello' as p return right(p, 3)

    replace

    2.3.11

    字符串替换

    with 'hello' as p return replace(p, 'll', 'o')

    split

    2.3.11

    字符串切割

    with 'hello' as p return split(p, 'e')

    表5 数学函数

    函数名

    支持的最低版本

    释义

    举例

    floor

    2.3.10

    向下取整

    return floor(4.1)

    ceil

    2.3.10

    向上取整

    return ceil(4.1)

    round

    2.3.14

    取整

    return round(3.4), round(3.5)

    abs

    2.3.14

    绝对值函数

    return abs(-3),abs(-3.5)

    sin

    2.3.14

    正弦函数

    return sin(pi()/2)

    cos

    2.3.14

    余弦函数

    return cos(0),cos(pi()/2)

    tan

    2.3.14

    正切函数

    return tan(pi()/4)

    acos

    2.3.14

    反余弦函数

    return acos(1)

    asin

    2.3.14

    反正弦函数

    return asin(0)

    atan

    2.3.14

    反正切函数

    return atan(1)

    cot

    2.3.14

    余切函数

    return cot(pi()/4)

    radians

    2.3.14

    度数转弧度

    return radians(180)

    degrees

    2.3.14

    弧度转度数

    return degrees(pi())

    pi

    2.3.14

    返回圆周率近似值

    return pi()

    表6 日期时间函数

    函数名

    支持的最低版本

    释义

    举例

    datetime(val)

    2.3.10

    根据时间戳返回时间

    return datetime(1688696395)

    datetime()

    2.3.14

    获取当前时间(仅读语句生效)

    return datetime()

    timestamp(val)

    2.3.10

    根据时间字符串返回时间戳

    return timestamp('2023-07-07 02:20:42')

    timestamp()

    2.3.14

    获取当前时间戳(仅读语句生效)

    return timestamp()

    localDatetime

    2.3.14

    将时间/时间戳转为本地时间字符串

    return localDatetime(timestamp())

    表7 谓词函数

    函数名

    支持的最低版本

    释义

    举例

    all

    2.2.19

    全部元素满足表达式,则返回true

    all (x in p where x>1)

    any

    2.2.19

    任意一个元素满足表达式,则返回true

    any (x in p where x>1)

    none

    2.2.19

    全部元素无法满足表达式,返回true

    none (x in p where x>1)

    single

    2.2.19

    有且仅有1个元素满足表达式,返回true

    single (x in p where x>1)

    表8 算法表达式

    函数名

    支持的最低版本

    释义

    举例

    shortestPath

    2.3.2

    返回两点间最短路

    给定点n,m 返回两点间最短路,方向为m到n,边label为rate:

    with n,m, shortestPath((n)<-[:rate*]-(m)) as p return p

    allShortestPaths

    2.3.2

    返回两点间全最短路集合

    给定点n,m 返回两点间全最短路集合:

    with n,m, allShortestPaths((n)-[*]-(m)) as p return p

说明:
  • sum()、avg()、max()、min()等聚集函数在持久化版规格暂不开放。
  • 度数类函数、路径操作类函数、算法表达式在百亿规格和持久化版规格暂不开放,toUpper和toLower函数在持久化版规格暂不开放。

过程

目前GES 支持如下过程(Procedure):

名称

语句

获取图模式相关信息

call db.schema()

获取点label

call db.labels()

查询当前正在执行的Cypher语句

call dbms.listQueries()

根据queryId终止某条Cypher语句

call dbms.killQuery('queryId')

查询索引

call db.indexes()

全文索引,查询符合要求的点

call db.index.fulltext.queryNodes()

全文索引,查询符合要求的边

call db.index.fulltext.queryRelationships()

合并节点

call apoc.refactor.mergeNodes(nodeList, refactorConfig)

说明:
  • 全文索引支持prefix(前缀)、wildcard(通配符)、regexp(正则)、fuzzy(模糊)、match(匹配)、combine(组合)6种查询,如果想使用全文索引的能力,需要预先调用创建全文索引的API。
  • 函数和过程名大小写敏感,须按小驼峰写法调用。
  • 全文索引查询请求示例:
    POST http://{SERVER_URL}/ges/v1.0/{project_id}/graphs/{graph_name}/action?action_id=execute-cypher-query
    {
        "statements": [
            {
                "statement": "call db.index.fulltext.queryNodes('combine', {title:'1977'}) yield node, score return node, score skip 1 limit 10",
                "resultDataContents": [
                    "row"
                ],
                "parameters": {}
            }
        ]
     }
  • 添加边时的平行边处理策略:

    通过cypher添加边的时候,允许添加重复边,此处的重复边的定义为<源点,终点>相同的两条边。

  • 添加无label的边的方法:

    通过Cypher添加边时必须指定label,所以指定待添加边的label为默认值”__DEFAULT__”即可,例如create ()-[r:__DEFAULT__]->() return r

通过Cypher查询Schema结构

  • 功能介绍

    查询生成的schema结构(从OBS上读取)。

  • 查询语句介绍
    • 名称:查询Schema结构。
    • 命令:call db.schema ()
    • 说明:

      当未执行生成Schema结构API时,返回schema文件中的所有label。

      当已执行生成Schema结构API时,以label为点,以label和label间关系为边返回。

我们使用cookie来确保您的高速浏览体验。继续浏览本站,即表示您同意我们使用cookie。 详情

文档反馈

文档反馈

意见反馈

0/500

标记内容

同时提交标记内容