2

The response returned by Neo4j's REST interfaces are very verbose - they return not only the data in each node requested, but also the full discoverability for every node requested. If I just want some node data, the results are about 20 times bigger than I actually need, and I run into problems with out-of-memory exceptions and the like.

For example, a request for a node might return the following:

{
  "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" ]
  }
}

Is there a way to reduce the amount of information returned in the response? All I really want for each node is this:

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

or even:

[ "908754897618956", "Active" ]

Is that achievable? When I'm requesting hundreds of thousands of nodes it makes quite a big difference.

Ken Williams
  • 22,756
  • 10
  • 85
  • 147
  • 1
    The Rest format is definitely too verbose. There are some planned modifications to the protocol used by the http tx endpoint in future versions. You might want to consider changing the resultDataContent to "graph" or "row" in order to have a less verbose response. http://neo4j.com/docs/stable/rest-api-transactional.html#rest-api-return-results-in-graph-format – Christophe Willemsen Apr 15 '15 at 18:26
  • Thanks Christophe, is there a corresponding option without using the transactional API? Right now I'm just hitting `/db/data/label/MyLabel/nodes`. – Ken Williams Apr 15 '15 at 19:51
  • not that I know. btw I think these endpoints are becoming less and less used in favor of the tx api. – Christophe Willemsen Apr 15 '15 at 20:05

1 Answers1

2

There is no config option to tweak this for the existing db/data/node REST endpoint.

As Christophe sketched you can use the transactional endpoint and a tailored Cypher statement to return those properties you want to see.

The other option is writing your own unmanaged extension to the Neo4j server that returns the nodes as you've specified.

The lowest hanging fruit is for sure the first approach.

Stefan Armbruster
  • 39,465
  • 6
  • 87
  • 97