【问题标题】:Neo4j - Reduce number of fields returned in REST responseNeo4j - 减少 REST 响应中返回的字段数
【发布时间】:2015-04-15 18:17:00
【问题描述】:

Neo4j 的 REST 接口返回的响应非常冗长——它们不仅返回请求的每个节点中的数据,还返回请求的每个节点的完整可发现性。如果我只想要一些节点数据,结果会比我实际需要的大 20 倍左右,并且会遇到内存不足异常等问题。

例如,对节点的请求可能会返回以下内容:

{
  "labels" : "http://giuncwy02:7475/db/data/node/67/labels",
  "outgoing_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/out",
  "data" : {
    "id" : "908754897618956",
    "currentStatus" : "Active",
  },
  "traverse" : "http://giuncwy02:7475/db/data/node/67/traverse/{returnType}",
  "all_typed_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/all/{-list|&|types}",
  "self" : "http://giuncwy02:7475/db/data/node/67",
  "property" : "http://giuncwy02:7475/db/data/node/67/properties/{key}",
  "outgoing_typed_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/out/{-list|&|types}",
  "properties" : "http://giuncwy02:7475/db/data/node/67/properties",
  "incoming_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/in",
  "extensions" : { },
  "create_relationship" : "http://giuncwy02:7475/db/data/node/67/relationships",
  "paged_traverse" : "http://giuncwy02:7475/db/data/node/67/paged/traverse/{returnType}{?pageSize,leaseTime}",
  "all_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/all",
  "incoming_typed_relationships" : "http://giuncwy02:7475/db/data/node/67/relationships/in/{-list|&|types}",
  "metadata" : {
    "id" : 67,
    "labels" : [ "Substation" ]
  }
}

有没有办法减少响应中返回的信息量?我真正想要的每个节点是这样的:

{
    "id" : "908754897618956",
    "currentStatus" : "Active",
}

甚至:

[ "908754897618956", "Active" ]

这可以实现吗?当我请求数十万个节点时,它会产生很大的不同。

【问题讨论】:

  • Rest 格式肯定太冗长了。在未来的版本中,http tx 端点使用的协议有一些计划的修改。您可能需要考虑将 resultDataContent 更改为“graph”或“row”,以减少冗长的响应。 neo4j.com/docs/stable/…
  • 谢谢 Christophe,有没有不使用事务 API 的对应选项?现在我只是打/db/data/label/MyLabel/nodes
  • 我不知道。顺便说一句,我认为这些端点越来越少用于支持 tx api。

标签: rest neo4j discoverability


【解决方案1】:

对于现有的db/data/node REST 端点,没有配置选项可以调整它。

正如 Christophe 所述,您可以使用事务端点和定制的 Cypher 语句返回您想要查看的属性。

另一个选项是将您自己的 unmanaged extension 写入 Neo4j 服务器,该服务器会返回您指定的节点。

最简单的方法肯定是第一种方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 2021-12-19
    • 2013-04-09
    • 1970-01-01
    相关资源
    最近更新 更多