Reputation: 809
I am sorry for the stupid question. I have two types of nodes in neo4j database, namely Recipes
and Meal_Type
. I am running a cypher query in neo4j that results all relationship between the two types of nodes. The query is not that special, it is the default query that returns relationship with a limit of 200 nodes.
MATCH ()-[r]->() RETURN r LIMIT 200
It is running fine. But I need, at least, all Meal_Types
nodes in result regardless the rest of result. Right now it is returning 3 (sometimes 4,5 on re-running query) out of 11 Meal_Types
.
Upvotes: 1
Views: 1070
Reputation: 11216
I think you should fetch all of the Meal_Type
nodes first and then with that result fetch a set of Recipe
nodes that correspond to it.
Here is an example of what I am talking about. Fetch all of the different meal types, unless of course you have some specific ones you are interested in. Then with those meal types return a sampling of the corresponding set of recipes (200 ~= 19 * 11).
// match meal types
MATCH (mt:Meal_Type)
WITH mt
// find a sampling of the the corresponding recipes.
MATCH (mt)<-[OF_TYPE]-(r:Recipe)
RETURN mt, collect(r)[0..18] AS recipe_sample
Upvotes: 3
Reputation: 11715
Really? I answered that yesterday with your previous question, it's just a variation.
This should do the trick, sorting the relationships by node label:
MATCH (n)-[r]-()
RETURN r
ORDER BY head(labels(n))
Upvotes: 0