0
votes

I'm parsing a cypher query to a .gexf (xml) file. Entering this query in the Neo4j admin gui returns all nodes with their interconnecting relationships (relations between all b-nodes)

START a=node(52681) MATCH(a)-[r]-(b) RETURN a,r,b

The neo4j webgui seems to make it's own queries since it draws up all the relationships between the b-nodes and not just between the a and b-nodes. The JSON response contains no data of which I can parse an xml file with the relationships between the b-nodes.

I've resolved this so far by doing a seperate query for each and every b-node:

MATCH (a)-[r]-(b) WHERE id(a)=52681 AND id(b)=12345

But that doesn't seem like very good design... I would like to get this done in one query only.

Also, I tend to overcomplicate things.

1
It's not clear you me what you are actually trying to do. Your title suggests that you are trying to query the entire graph structure, but you don't mention that in the detail. Can you clarify?Ben Butler-Cole

1 Answers

0
votes

I don't think there's an easy/efficient way to do this.

Consider that the paths between each pair of nodes are likely variable in size, and therefore something like (a)-[r]-(b) will only get you the results you want if a and b are both one degree away.

If they are, however, all only one degree away (and assuming no self-loops, which would be easy enough to take care of anyway), something like

MATCH (a)-[r]-(b) RETURN a, r, b

...would likely do the trick, albeit in a horribly inefficient fashion. But if your paths between a and b are > 1 level deep, it obviously won't work.

In that case, something like this might work, but again be horrible:

MATCH (a)-[r:*]-(b) RETURN a, r, b

...but if the depth of your paths are anything more than a few levels, well...ouch.

When you start asking questions of the graph that span the entire graph and require working/traversing the entirety of it, the kinds of questions you're asking start to blow up a bit.

So, likely, the resolution you came up with is probably the only way to really tackle this.

That said, I'd love to know if anyone else has a different take on this.

HTH, if only a bit.