I have a graph in neo4j with 100 million nodes. I created an unique constraint on a property but when I use the property in my where clause it returns no rows. I know it has a result but returns no rows.
my Cypher query is like below:
MATCH(n:Person{PK:'1'})
RETURN n
or
MATCH(n:Person)
WHERE n.PK='1'
RETURN n
Can you try to use :schema in the browser to check your constraint?
Also note that it is case sensitive, both for the label and the key.
Just because you have a unique constraint doesn't mean that you have data, in this case a person, with that property. Try just pulling up a person and seeing what properties are set.
match (p:Person) return p limit 5;
My suspicion is that the problem is in how you are creating the Person nodes. Can you share that code with us?
Related
I have a neo4j db which have this form
(:FBuser)-[:Published]->(:Post)<-[:Tagged_in]-(:Friend)<-[:Tagged_together]->(:Friend)
A Post (:Node) could have two or more Nodes (:Friend) connected with it.
I want to write a query that returns this schema
(:FBuser)-[:Friend]->(n:Friend)-[:Tagged_in]->(:Post)<-[:Tagged_in]-(m:Friend)<-[:Tagged_together]->(n)
where for (:Post) I need all the post for that specific (n:Friend). The problem is that not all the (:Post) has connected with another (m:Friend) so, only for some nodes I have (n:Friend)<-[:Tagged_together]->(m:Friend)
I write this code but obviously returns just all the nodes (:Post) for a specific node (:Friend) and supplementary (:Friend) connected with it
MATCH t=(:fbUser)-[:FRIEND]-(w)-[:TAGGED_IN]-(p)
MATCH s=(:Friend)-[:TAGGED_IN]-(q)
WHERE
w.name=~ '(?i).*edoardo.*' AND
q.timestamp=p.timestamp AND
w.nodeDegree>=0
RETURN t,s
How can I solve the problem ?
Try optional match. https://neo4j.com/docs/cypher-manual/current/clauses/optional-match/
I used a coalesce statement so that the timestamp filter will still return records if q is null.
MATCH t=(:fbUser)-[:FRIEND]-(w)-[:TAGGED_IN]-(p)
OPTIONAL MATCH s=(:Friend)-[:TAGGED_IN]-(q)
WHERE
w.name=~ '(?i).*edoardo.*' AND
coalesce(q.timestamp, p.timestamp)=p.timestamp AND
w.nodeDegree>=0
RETURN t,s
I have a query that I am trying to execute. The query works, but there isn't an option to see this data in graph format. Instead the data is returned in table/text format.
When I simplify the query, the output is displayed in graph format - No idea why,
This is the query that is giving me the issue:
MATCH (p:Person)-[hi:hasIdentity]->(i:Identity)
MATCH (j:Person)-[hi2:hasIdentity]->(i2:Identity)
MATCH (i)-[bl:Linked]->(i2)
WHERE NOT p=j
return DISTINCT(p.id), COUNT(DISTINCT(j))
LIMIT 5
Does anyone have any idea why that might be the case?
You'll need to return variables associated with nodes and/or relationships for it to display as a graph. As it is now you're returning properties of nodes (p.id), probably integers or strings. Try this return instead:
...
RETURN p, COUNT(DISTINCT j)
LIMIT 5
By the way, DISTINCT isn't a function, no need for parenthesis, and when you have a RETURN or WITH that has an aggregation, you don't need to use DISTINCT for that line since the non-aggregation variables become distinct since they act as the grouping key for the aggregation.
I'm new to neo4j and I'm stuck on a simple problem:
create (machine1:host);
match (n) where n.host='machine1' return n;
The match fails. When using explain I see this:
The provided property key is not in the database
One of the property names in your query is not available in the database, make sure you didn't misspell it or that the label is available when you run this statement in your application (the missing property name is: host)
What am I doing wrong? Thanks for everyone's time.
You should know the difference between labels and properties.
A label is a grouping facility for Node where all nodes having a label are part of the same group.
I think you should use Machine label for Nodes which represents machines.
And you should use host property to store its name value.
create (:Machine {host:'machine1'});
match (n) where n.host='machine1' return n;
or even better:
match (n:Machine) where n.host='machine1' return n;
I have a Neo4J DB up and running with currently 2 Labels: Company and Person.
Each Company Node has a Property called old_id.
Each Person Node has a Property called company.
Now I want to establish a relation between each Company and each Person where old_id and company share the same value.
Already tried suggestions from: Find Nodes with the same properties in Neo4J and
Find Nodes with the same properties in Neo4J
following the first link I tried:
MATCH (p:Person)
MATCH (c:Company) WHERE p.company = c.old_id
CREATE (p)-[:BELONGS_TO]->(c)
resulting in no change at all and as suggested by the second link I tried:
START
p=node(*), c=node(*)
WHERE
HAS(p.company) AND HAS(c.old_id) AND p.company = c.old_id
CREATE (p)-[:BELONGS_TO]->(c)
RETURN p, c;
resulting in a runtime >36 hours. Now I had to abort the command without knowing if it would eventually have worked. Therefor I'd like to ask if its theoretically correct and I'm just impatient (the dataset is quite big tbh). Or if theres a more efficient way in doing it.
This simple console shows that your original query works as expected, assuming:
Your stated data model is correct
Your data actually has Person and Company nodes with matching company and old_id values, respectively.
Note that, in order to match, the values must be of the same type (e.g., both are strings, or both are integers, etc.).
So, check that #1 and #2 are true.
Depending on the size of your dataset you want to page it
create constraint on (c:Company) assert c.old_id is unique;
MATCH (p:Person)
WITH p SKIP 100000 LIMIT 100000
MATCH (c:Company) WHERE p.company = c.old_id
CREATE (p)-[:BELONGS_TO]->(c)
RETURN count(*);
Just increase the skip value from zero to your total number of people in 100k steps.
I have a problem in querying for two nodes with one similar property, one different property and having the same label. For one property, the property is the same between both nodes, i.e. both have a property called "Name" and both have the same value ("Data Storage"). For the other property though called "Note", they have different values. Both share the same label called "Issue". When I use the query below, I get both nodes.
match (n:Issue) where n.name="Data Storage" return n;
However, when I query with the following query...
match (n:Issue) where n.name="Data Storage" and n.note="xxxx" return n;
...it only works for one of the nodes and not for the other. I've tried creating the node which doesn't query and it seems to work fine. But I also did it with a different label. Is this some bug around not being able to query a node having the same label and sharing at least one common property?
match (n:Issue) where n.name="Data Storage" and n.note="xxxx" return n;
will match all nodes with label Issue, the value of the "name" property = "Data Storage" AND the value of the "note" property = "xxxx".
As you've described the 2 nodes, the value of the note property is different on each. The one matching xxxx is the only one that can be returned.
What is the goal of this query?
If this was your real question.
Query a node having the same label and sharing at least one common property?
you can try this for each property and do a union over all
MATCH (n:Issue)
WITH n.name, collect(n) as nodes, count(*) as cnt
WHERE cnt > 1
RETURN nodes
or this will be less performant
MATCH (n:Issue)
WITH n
MATCH (m:Issue)
WHERE m<>n AND (n.name = m.name OR n.note = m.note)
RETURN n,m