[Neo4j] Cypher request with where clause on relations count

Michael Hunger michael.hunger at neotechnology.com
Wed Jul 20 19:54:41 CEST 2011


sorry, your mail seem to have slipped through the cracks.

Aggregate functions in the where clause don't work.
We intend to add a having clause to cypher in the 1.5 timeframe. 

Then it should be possible to do something like this.

> start A=(id,object_type,"A") match (A)-[r:USES]->(B) return count(A) having count(r)=1 

At the moment I'm not sure how to achieve that with a single REST traversal.

In Java code:

int counter  = 0;
Index<Node> typeIndex = gdb.index().forNodes("id");
for (Node a : typeIndex.get("object_type","A")) {
    Iterable rels = a.getRelationships(USES,Direction.OUTGOING).iterator();
    // wrap the next three lines in a method
    if (!rels.hasNext()) continue;
    if (rels.hasNext()) continue;
    counter ++;
return counter;

Am 15.07.2011 um 18:20 schrieb Allee, Guillaume:

> Hi,
> I have 2 kind of nodes (let's say A and B) which are related using a relation of type 'USES'.
> I want to count all the type A nodes which have only 1 relation to B type node and all the type A nodes which have more than one relation to B type node.
> I am using neo4j server and I am currently trying to make a cypher request for that : it would look like that :
> start A=(id,object_type,"A") match (A)-[r:USES]->(B) where count(r)=1 return count(A)
> It is possible to make that kind of request with Cypher ?  If not, how would you do it with Neo4j server ?
> Cheers,
> Guillaume ALLEE | Capgemini | BTech Toulouse
> </PRE><p style="font-family:arial;color:grey" style="font-size:13px">This message contains information that may be privileged or confidential and is the property of the Capgemini Group. It is intended only for the person to whom it is addressed. If you are not the intended recipient, you are not authorized to read, print, retain, copy, disseminate, distribute, or use this message or any part thereof. If you receive this message in error, please notify the sender immediately and delete all copies of this message.</p><PRE>
> _______________________________________________
> Neo4j mailing list
> User at lists.neo4j.org
> https://lists.neo4j.org/mailman/listinfo/user

More information about the User mailing list