I wanted to write a query that can give an attribute name search where it has an attribute name matching a provided name.
For example, return the nodes where any node has an attribute e.g. named "value". Not a value of "value" but an attribute named value.
The result list should output
"The following nodes have attributes named "value":
Bow this heading, show results in rows where the columns of the rows shown are:
node id, node label(s)
The result list should output
"The following nodes have attributes named "value":
Obviously replace “value” with whatever the attribute name was given in query Preformatted text
Query:
with "value" as m
match (n) where m in keys(n)
return n as The following nodes have attributes named+[m]
I have checked the google and Neo4j docs but couldn't find a way to do that. Any help would be appreciated!
Thank you in advance!
I think, I am not able to explain my problem. I able to run below query successfully with out any error and it is giving the required nodes but my client want specific text "The following nodes have attributes named: value". "Value" is the string which user is searching. So we can't hard code it. So I want searched string at the end but not getting the way to do.
with "value" as m
match (n) where m in keys(n)
with n, collect(distinct labels(n)) as lbls
return n as `The following nodes have attributes named:`
Try this:
match (c) where exists (c.value)
with collect(distinct labels(c)) as the_following_labels_have_value_as_property
return the_following_labels_have_value_as_property
This doesn't really have to do with what's happening before or after a RETURN, this has to do with limitations for how we are allowed to alias variables in Cypher, since what you're actually trying to do is alias a variable such that the variable is assembled dynamically.
And that currently isn't allowed. Aliases for variables must be hard coded in the query, they cannot be dynamic.
What you could do, in your client code that is going to make the query to Neo4j, is to dynamically append the value into the query string before you send that off to Neo4j for execution, so once it reaches Neo4j, it is essentially hardcoded.
Or, if you want to handle this entirely within the Cypher query itself, you can create a map with a dynamic key, and return that map, but you'll have to use some functions from APOC Procedures to do this:
WITH "value" as m
MATCH (n)
WHERE m in keys(n)
WITH m, collect(n) as nodes
WITH nodes, "The following nodes have attributes named '" + m + "'" as key
RETURN apoc.map.fromValues([key, nodes]) as result