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.

Add symbolic name to all nodes/edges with missing alias in cypher query

Hi all. My usecase requires that I run any given neo4j cypher query on my application and I am providing some filters over these queries. For that I am using the aliases for each node/edge in the user entered cypher query.

But if the user doesnot mention any alias, then my filtering condition would not be applied on that particular node/edge. 

eg: match (a:NODE_1)-[:Has]-(:NODE_2) return path. 

Filtered query: match (a:NODE_1)-[:Has]-(:NODE_2) where a.SOME_CONDITION = 'zyx' return path

Here I wont be able to apply filter on the node_2 node and Has edge and thus my result might be incorrect.

Is there some way using the neo4j-cypher-dsl library(or some other way) that i can add aliases to the missing nodes/edges in query? If so, please help me with that. Thanks.

3 REPLIES 3

Not sure what you mean, as you can alias all the entities, such as:

match path=(a:NODE_1)-[r:Has]-(b:NODE_2) 
where a.SOME_CONDITION = 'zyx' 
and r.SOME_CONDITION = 'abc'
and b.SOME_CONDITION = 'def'
return path

Sorry thats not what I intended to ask. I am building an application where a user can enter a cypher query and I have to modify it so as to add some filtering conditions or some other modifications according to the usecase.

So if a user enters match (a:NODE_1)-[:Has]-(:NODE_2) return path then i will be getting this as the query string. Now I have to modify this query to add aliases to all the missing nodes/edges. I know this can be achieved using java using regex match but i was wondering if neo4j cyherdsl library supports such a functionality. @glilienfield 

Aren't you still going to have to parse the string and convert it to cypher DSL equivalent code? 

Here is the DSL manual: https://neo4j-contrib.github.io/cypher-dsl/current/

Here is code a pulled from the first page of the manual. The first line creates a Movie node aliased to 'm'. 

var m = Cypher.node("Movie").named("m"); 
var statement = Cypher.match(m) 
    .returning(m)
    .build(); 

assertThat(cypherRenderer.render(statement))
    .isEqualTo("MATCH (m:`Movie`) RETURN m");

 

 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online