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.

Creating graph in gds

andy_hegedus
Graph Fellow

Hi,
New to this and practicing creating subgraphs with gds.
My simple objective is to create a subgraph of recipes that have capers and are main courses. Per the documentation I need to define id, source and target. I am not completely clear how to assign target since in this query in the browser is
MATCH (:Ingredient{name:"capers"})-[:HAS_INGREDIENT]-(a:Dish)-[:DISH_TYPE]-(b:DishType{name:"main course"}) RETURN a
Works as intended.

I have tried to assign it more or less as a dummy variable since it is required. BUT this does not work.
with a failed to load relationship with unknown target-node id 3660.

CALL gds.graph.create.cypher('caper_main',
'Match (a:Dish) RETURN id(a) as id, a.name as recipe',
'MATCH (:Ingredient{name:"capers"})-[:HAS_INGREDIENT]-(a:Dish)-[:DISH_TYPE]-(b:DishType{name:"main course"}) RETURN id(a) AS source, id(b) AS target')

What am I missing?
Andy

4 REPLIES 4

genealogy
Graph Buddy

The subgraph will be in memory. Is it in the list of available graphs after you run the above create?

call gds.graph.list()

If so, have you tried querying it? Something like:

call gds.louvain.stream("myGraph")
YIELD nodeId, communityId, intermediateCommunityIds
RETURN nodeId, communityId, intermediateCommunityIds

Hi genealogy,

The graph is not in memory as per gds.graph.list().
Andy

andy_hegedus
Graph Fellow

Hi,
Made a tweak but not sure what I am getting. Changed the node query to 'MATCH (a) RETURN id(a) AS id'
It returns a node count of 3682 which is all the nodes in the database and 134 relationships. When I run from the browser I get 134 nodes.

CALL gds.graph.create.cypher('capers', 'MATCH (a) RETURN id(a) AS id', 'MATCH (Ingredient{name:"capers"})-[:HAS_INGREDIENT]-(a:Dish)-[:DISH_TYPE]-(b:DishType{name:"main course"}) RETURN id(a) as source, id(b) AS target')

If I do this as the node query

'MATCH (a:Dish) RETURN id(a) AS id',

I get an error which references node id 3660.
If I do:

Match (a)
WHERE id(a)=3660
RETURN a

It returns the node for DishType{name:'main course}

Is this the correct expectation of how it should work? I am confused.
Andy

ameyasoft
Graph Maven
You have a blank space in the node name. In this case, try using  backtick:

(b:DishType{name:`main course`})