Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-23-2020 01:55 AM
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?
Solved! Go to Solution.
04-23-2020 04:17 PM
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.
04-23-2020 04:17 PM
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.
04-23-2020 05:26 PM
Wayyyy overthought it.
This is great thanks so much for your help.
Glad to be part of the community, thanks again.
04-23-2020 05:02 PM
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:
04-23-2020 05:27 PM
Hi Andrew,
Great article, I followed it to get my original query but I just overthought it.
Appreciate the help thank you
All the sessions of the conference are now available online