I am searching for a cypher query that returns me the current data-model, meaning every node plus relationship, but only once.
I did find the query already in the past via stackoverflow.com or google, but I did not find it now again making a research.
Thank you
I think what you're looking for is CALL db.schema.visualization
The output for the Movie Graph is:
Related
I am using one of the neo4j practice graphs (see below) to learn cypher
and running a query to search for people who both acted int and directed a movie, I'm running the following commands:
:play movie graph
MATCH (p:Person)-[a:ACTED_IN]->(m:Movie)<-[d:DIRECTED]-(p)
RETURN p,m,a,d,type(a),type(d)
I few things don't make sense:
for some rows in the result type(a) is not ACTED_IN but
PRODUCER or WROTE etc.
a lot of nodes are returned which don't seem to satisfy this pattern
using OPTIONAL MATCH works exactly right but I don't know why?
Any help would be much appreciated
As cybersam commented, this definitely looks like a bug in the compiled runtime.
If you PROFILE this you can see it's using compiled runtime; if you prefix the query with CYPHER runtime=slotted we get expected results.
I'll pass this along to the cypher team.
I have a Neo4j Graph database which stores Twitter data.
Each Tweet is about a Topic and has got this kind of relationship:
(t:Tweet)-[:ABOUT]->(t1:Topic)
A User can be mentioned by a Tweet due to this relationship
(t:Tweet)-[:MENTIONS]->(u:User)
I'd like to know how many users are mentioned in tweets regarding a specific topic.
My query is:
match (n:Topic)<--()-[r:MENTIONS]->(u:User)
where n.name='politics'
return count(r)
Is this query right? Because I've got unexpected results.
Thanks a lot.
You can try using the following query.
match (n:Topic{name:'politics'})
RETURN size((n)<--()-[:MENTIONS]->(:User)) as count
I'm using neo4j and making executing this query:
MATCH (n:Person) RETURN n.name LIMIT 5
I'm getting the names but i need the ids too.
Please help!
Since ID isn't a property, it's returned using the ID function.
MATCH (n:Person) RETURN ID(n) LIMIT 5
Not sure how helpful or relevant this is, but when I'm using the NodeJS API the record objects returned from Cypher queries have an identity field on the same level as the properties object (e.g record.get(0).properties, record.get(0).identity). I'm assuming you aren't just doing plain Cypher queries and actually using a driver to send the queries - so you might not have to run another MATCH statement.
I'm aware that the OP is asking about Cypher specifically - but it might be helpful to other users that stumble upon this question.
Or you can take a look on the Neo4j Cypher Refcard
You can get a short look to a lots of functions and patterns you can write.
And more about functions on The Neo4j Developer Manual - Chapter 3. Cypher - 3.4. Functions
I'm pretty new to Neo4j; I've only gotten as far as writing a hello world. Before I proceed, I want to make sure I have the right idea about how Neo4j works and what it can do for me.
As an example, say you wanted to write a Neo4j back end for a site like this. Questions would be nodes. Naïvely, tags would be represented by an array property on the question node. If you wanted to find questions with a certain tag, you'd have to scan every question in the database.
I think a better approach would to represent tags as nodes. If you wanted to find all questions with a certain tag, you'd start at the tag node and follow the relationships to the questions. If you wanted to find questions with all of a set of tags, you'd start at one of the tag nodes (preferably the least common/most specific one, if you know which one that is), follow its relationships to questions, and then select the questions with relationships to the other tags. I don't know how to express that in Cypher yet, but is that the right idea?
In my real application, I'm going to have entities with a potentially long list of tags, and I'm going to want to find entities that have all of the requested tags. Is this something where Neo4j would have significant advantages over SQL?
Kevin, correct.
You'd do it like that.
I even created a model some time ago for stackoverflow that does this.
For Cypher you can imagine queries like these
Find the User who was most active
MATCH (u:User)
OPTIONAL MATCH (u)-[:AUTHORED|ASKED|COMMENTED]->()
RETURN u,count(*)
ORDER BY count(*) DESC
LIMIT 5
Find co-used Tags
MATCH (t:Tag)
OPTIONAL MATCH (t)<-[:TAGGED]-(question)-[:TAGGED]->(t2)
RETURN t.name,t2.name,count(distinct question) as questions
ORDER BY questions DESC
MATCH (t:Tag)<-[r:TAGGED]->(question)
RETURN t,r,question
I'm just starting to learn about Neo4J and I thought up a question I haven't seen an answer to in the reading I've been doing so far.
I believe it's possible for a Node to be connected to another Node with the same relationship multiple times.
Is it possible to return only the nodes where the number of Relationship edges meets some criteria?
Example:
Friend is a node.
Poked is a relationship.
Friend A has poked Friend B
Friend A has poked Friend B
Friend B has poked Friend C
How would I query this so only Friend A is selected because it has poked the same friend more than once?
If it matters; I'll be using Java and Spring's Data Graph module.
I'm assuming you want to use Cypher. Who wouldn't, right?
Cypher doesn't have the SQL equivalent of HAVING, so you will have to do a little bit in your host language. The query would look something like this:
START friendA=node:person(name="Michael")
MATCH friendA-[:POKED]->friendB
RETURN friendB, count(*)
Now, with the resulting iterable of maps, exclude from the final result all maps where count(*) is different from what you want it to be.
Does this make sense?