cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Group nodes by property type

Hi, I'm trying to aggregate returned nodes by an amount of property types.

Basically I have (r:Recipe)-[:HAS_CUISINE]->(c:Cuisine)

I'd like to return 10 recipes from each Cuisine in my database

I feel like it should be something close to

MATCH(c:Cuisine)
WITH collect(DISTINCT c.name) as cuisines
UNWIND cuisines as cuisine
apoc.cypher.run('
MATCH(r:Recipe)-[:HAS_CUSINE]->(c:Cuisine {name: cuisine})
RETURN r LIMIT 10
', {cuisine: cuisine}) YIELD value
RETURN value.r as recipes
LIMIT 100

The problem I keep running into is I only ever get 10 recipes back.

what could I be doing wrong here?

1 ACCEPTED SOLUTION

webtic
Graph Fellow

Hi Markkdev, welcome to the community!

One way of getting the information is with this query:

match (r:Recipe)-[HAS_CUISINE]-(c) WITH c,collect(r)[0..10] as recipes return c,recipes

This gets 10 recipes at most from each cuisine and returns both the recipes and the cuisine.

From what I gather from your query you were overthinking the problem
There is really no need to use APOC for queries like these.

View solution in original post

4 REPLIES 4

webtic
Graph Fellow

Hi Markkdev, welcome to the community!

One way of getting the information is with this query:

match (r:Recipe)-[HAS_CUISINE]-(c) WITH c,collect(r)[0..10] as recipes return c,recipes

This gets 10 recipes at most from each cuisine and returns both the recipes and the cuisine.

From what I gather from your query you were overthinking the problem
There is really no need to use APOC for queries like these.

Wayyyy overthought it.

This is great thanks so much for your help.

Glad to be part of the community, thanks again.

I have a knowledge base article on exactly this issue, with some approaches you can use to get the limited results per row you're after:

Hi Andrew,

Great article, I followed it to get my original query but I just overthought it.

Appreciate the help thank you