Creating relationship between two previously disconnected nodes - neo4j

Given query:
start n=node(*)
match p:Person, b:Book
where p.name = 'John' AND b.title = 'KJV'
create p-[r:OWNS]->b
return r
error: Expected return clause is thrown, with a caret pointing at the S]
What is the syntactical error?

May be you are using older version of Neo4j (< 2.0) which doesn't support Labels. I was able to successfully create the relationships using the below Cypher. Tried it on console.neo4j.org
CREATE (n:Person { name : 'John' })
CREATE (n:Book { title : 'KJV' })
start n=node(*)
match p:Person, b:Book
where p.name = 'John' AND b.title = 'KJV'
create p-[r:OWNS]->b
return r
EDIT
As I've guessed, you are using 1.9.2 which doesn't support Labels. You however are using the Neo4j 2.0 syntax with Labels (p:Person, b:Book)

Related

Neo4j Matching Variable number of relationships from previous query

The code on the Neo4j docs shows the following for matching against a variable number of relationships.
MATCH (charlie { name: 'Charlie Sheen' })-[:ACTED_IN*1..3]-(movie:Movie)
RETURN movie.title
I am trying to do this based on a previous query using a WITH statement but cannot find the right syntax. Everything I try yields an error. I am aiming for something of the form:
MATCH p = ...
...
WITH length(p) AS len_p
MATCH (charlie { name: 'Charlie Sheen' })-[:ACTED_IN*len_p..len_p]-(movie:Movie)
RETURN movie.title
However, this syntax yields Neo.ClientError.Statement.SyntaxError.
What is the recommended way to do this?
[EDITED]
You can use the apoc.path.expandConfig procedure to perform variable-length relationship queries with dynamic bounds.
For example (to get paths of length len_p consisting of ACTED_IN relationships ending in a Movie node):
...
WITH length(p) AS len_p
MATCH (charlie:Person {name: 'Charlie Sheen'})
CALL apoc.path.expandConfig(charlie, {
relationshipFilter: 'ACTED_IN',
labelFilter: '>Movie',
minLevel: len_p,
maxLevel: len_p
}) YIELD path
RETURN LAST(NODES(path)).title AS title

py2Neo.ogm shortestPath search not turning up results

I have implemented py2neo with ogm, however I cannot get the search functionality to work like it should. Below I have my cypher query (directly to the Neo4j db) with 'rpt_id' and 'country_code' as GraphObjects in the graph with those as the primary keys of the graph. The relationship between them is PART_OF.
MATCH (m:Column {name: '{rpt_id}'}), (n:Column {name:'{country_code}'}),
p = shortestPath((m)-[:PART_OF*..4]-(n))
RETURN p
I expect a response of the Tables (another ogm node) to go through to get to country_code, however, nothing is being returned.
If nodes definitely exist that match rpt_id and country_code I expect the problem is the use of ticks around your parameters. I would re-write the query as follows:
MATCH (m:Column {name: {rpt_id} }), (n:Column {name: {country_code} }), p = shortestPath((m)-[:PART_OF*..4]-(n))
RETURN p

cypher query to get all relationship for a node doesn't return graphical representation in 3.1

I upgraded neo4j community edition from 3.0.3 to 3.1 and this query doesn't return graphical representation of all the relationships for this node anymore.
MATCH (:User {username: 'user6'})-[r]-()
RETURN r
Any reasons why it wouldn't work in 3.1?
Looks like the browser requires you to return nodes in order to see the graphical view. Just add variables on your start and end nodes and return them.
MATCH (a:User {username: 'user6'})-[r]-(b)
RETURN r, a, b
'r' refers to a relationship on its own. To return a graph you need the node(s) as well.
Try
MATCH graph = (a:User {username: 'user6'})-[r]-(b)
RETURN graph

Find Neo4j nodes where the property is not set

Using Cypher, how can I find a node where a property doesn't exist?
For example, I have two nodes:
A = {foo: true, name: 'A'}, B = { name: 'B'}
Now I'd like to find B, selecting it on the basis of not having the foo property set. How can I do this?
As Michael Hunger mentioned
MATCH (n) WHERE NOT EXISTS(n.foo) RETURN n
On older versions of Neo4j you can use HAS:
# Causes error with later versions of Neo4j
MATCH (n) WHERE NOT HAS(n.foo) RETURN n
As of version 4.3 EXISTS has been deprecated on properties and instead, you should use IS NOT NULL.
So for the example in your question your query would now be:
MATCH (n) WHERE n.foo IS NULL RETURN n
MATCH (f) WHERE f.foo IS NULL RETURN f

START command doesn't work in neo4j 2.0 RC1..?

I am using Neo4j 2.0 RC1. Problem comes from very simple command:
START n=node:nodes(name = "A")
RETURN n
But my Browser return: "Unknown error" like bellows picture
Could someone pls tell me how to fix this problem...??
did you create and populate an index named "nodes" upfront? If you didn't and don't want to, go with
MATCH (n) WHERE n.name = "A" RETURN n
or
MATCH (n:Label) WHERE n.name = "A" RETURN n
Start is depreciated in 2.0, though the tutorials might not all be updated yet to reflect it. Instead of Start, use Match:
Match (n:Label)

Resources