Cypher Query In Bloom and passing parameter

Hi,
Trying to craft a simple query where the depth of the relationship is subject to user input.
My search phrase is
Find $numlevels levels away from $cpcstart
where $numlevels is defined as an integer
and $cpcstart is node name property key

Match p=(A:cpc{subgroup:$cpcstart})-[:Reports_to*0..$numlevels]-(:cpc)

This returns error with this explanation
Parameter maps cannot be used in MATCH patterns (use a literal map instead, eg. "{id: {param}.id}") (line 1, column 61 (offset: 60))
"EXPLAIN Match p=(A:cpc{subgroup:$cpcstart})-[:Reports_to*0..$numlevels]-(:cpc)"
Return p
Which is the start of the relationship definition.

Now if I fix the depth of relationship search to specific degree with this search phrase
Match p=(A:cpc{subgroup:$cpcstart})-[:Reports_to*0..5]-(:cpc)
Return p
This is ok.

So how do I craft this to allow the user to define the depth degree of the search?
Andy

Hello @andy_hegedus
Bloom is using the cypher parameters it is not possible to parametrise a query in this way:

MATCH p=(a)-[*..$level]-()
RETURN p

An alternative query would be moving the filtering in the where clause

MATCH p=(a)-[*..5]-()
WHERE length(p)=$level
RETURN p
LIMIT 10

This query works but can be improved from a performance perspective.

We suggest you to install APOC plugin and use the Expands Path function:

MATCH (a:Film {wikiTitle: "The Matrix"})
CALL apoc.path.expand(a, null, null, 1, $level)
YIELD path
RETURN path

In your case it would be something like:

MATCH (a:cpc {subgroup: $cpcstart})
CALL apoc.path.expand(a, "Reports_to", ">cpc", 1, $level)
YIELD path
RETURN path

Hope this help!
/Claudio

1 Like

Hi Claudio,

Thank you very much! This is perfect and I also learned something new. For some reason I was not aware of the use of APOC procedures from within Bloom.
Andy