Amazon Neptune openCypher HTTPS 端点 - Amazon Neptune

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

Amazon Neptune openCypher HTTPS 端点

HTTPS 端点上的 openCypher 读取和写入查询

openCypher HTTPS 端点支持同时使用 GETPOST 方法执行读取和更新查询。不支持 DELETEPUT 方法。

以下说明将带您演练使用 curl 命令和 HTTPS 连接到 openCypher 端点。您必须在 Neptune 数据库 EC2 实例所在的虚拟私有云 (VPC) 中的 Amazon 实例中按照这些说明进行操作。

语法如下:

HTTPS://(the server):(the port number)/openCypher

以下是示例读取查询,一个使用 POST,一个使用 GET

1. 使用 POST

curl HTTPS://server:port/openCypher \ -d "query=MATCH (n1) RETURN n1;"

2. 使用 GET(查询字符串采用 URL 编码):

curl -X GET \ "HTTPS://server:port/openCypher?query=MATCH%20(n1)%20RETURN%20n1"

以下是示例写入/更新查询,一个使用 POST,一个使用 GET

1. 使用 POST

curl HTTPS://server:port/openCypher \ -d "query=CREATE (n:Person { age: 25 })"

2. 使用 GET(查询字符串采用 URL 编码):

curl -X GET \ "HTTPS://server:port/openCypher?query=CREATE%20(n%3APerson%20%7B%20age%3A%2025%20%7D)"

默认 openCypher JSON 结果格式

默认情况下或通过将请求标头显式设置为 Accept: application/json,返回以下 JSON 格式。这种格式旨在使用大多数库的原生语言特征轻松解析为对象。

返回的 JSON 文档包含一个字段 results,其中包含查询返回值。以下示例显示了常用值的 JSON 格式。

值响应示例:

{ "results": [ { "count(a)": 121 } ] }

节点响应示例:

{ "results": [ { "a": { "~id": "22", "~entityType": "node", "~labels": [ "airport" ], "~properties": { "desc": "Seattle-Tacoma", "lon": -122.30899810791, "runways": 3, "type": "airport", "country": "US", "region": "US-WA", "lat": 47.4490013122559, "elev": 432, "city": "Seattle", "icao": "KSEA", "code": "SEA", "longest": 11901 } } } ] }

关系响应示例:

{ "results": [ { "r": { "~id": "7389", "~entityType": "relationship", "~start": "22", "~end": "151", "~type": "route", "~properties": { "dist": 956 } } } ] }

路径响应示例:

{ "results": [ { "p": [ { "~id": "22", "~entityType": "node", "~labels": [ "airport" ], "~properties": { "desc": "Seattle-Tacoma", "lon": -122.30899810791, "runways": 3, "type": "airport", "country": "US", "region": "US-WA", "lat": 47.4490013122559, "elev": 432, "city": "Seattle", "icao": "KSEA", "code": "SEA", "longest": 11901 } }, { "~id": "7389", "~entityType": "relationship", "~start": "22", "~end": "151", "~type": "route", "~properties": { "dist": 956 } }, { "~id": "151", "~entityType": "node", "~labels": [ "airport" ], "~properties": { "desc": "Ontario International Airport", "lon": -117.600997924805, "runways": 2, "type": "airport", "country": "US", "region": "US-CA", "lat": 34.0559997558594, "elev": 944, "city": "Ontario", "icao": "KONT", "code": "ONT", "longest": 12198 } } ] } ] }