FAQ Database Discussion Community


How to return only nodes that matches all relationships in a Cypher query?

neo4j,cypher
Supposing I have the following relationships, how can I return all nodes connected to 3, 4 and 5 (node 1), but ignore nodes that have some of them, but not all (nodes 2 and 3). 1--4 1--5 1--6 2--4 3--5 3--6 ...

Checking NULLS in an OPTIONAL MATCH

neo4j,cypher
I have a cypher query like this: MATCH (start:StartLabel) OPTIONAL MATCH (start)-[:A]->(end1:EndLabel) OPTIONAL MATCH (start)-[:B|C]->(middle:MiddleLabel)-[:D]->(end2:EndLabel) WHERE NOT(end1 IS NULL AND end2 IS NULL) RETURN * In this graph model there are multiple valid ways to reach (end) from (start) but I want to make sure that the result matches at...

get nodes from LENGTH(r)

neo4j,cypher
This code MATCH (n { name: 'Create node' })<-[r*]-(s { name: ';' }) WITH n,s, LENGTH(r) AS depth RETURN n,s, depth will return amount of relationships between first and last nodes. Is it possible to get nodes that in that relationships? Bonus question: is it possible to get them in...

Neo4j speed of failure

neo4j,cypher
I am using embedded Neo4j with Java and generating queries automatically that vary in the number of relations they try to match and whether these relations are optional or not. This is an example of a query with optional relations: MATCH (target:C4)-[rvara:IN_LOCATION]->(nvara:LOCATION) OPTIONAL MATCH (nvara:LOCATION)-[rvarb:CONNECTED]->(nvarb:LOCATION) OPTIONAL MATCH (nvarc:LOCATION)-[rvarc:CONNECTED]->(nvara:LOCATION) OPTIONAL MATCH...

How to use wildcards at the beginning of property value?

neo4j,cypher,wildcard
i need something like that... match (n)-[:RELATIONSHIP]-(NODE) where NODE.name=~ "*.(?i)something.*" Return n.name The wildcard at the end is working. But the other won't. Thanks....

End UNWIND statement in a Cypher Query

neo4j,cypher
If I have a cypher query that unwinds a parameter, everything after that portion of the query is called x number of times of the unwind. I'd like to figure out a way to end the unwind and continue with other things. MATCH (thing:Thing) UNWIND { names } AS name...

Ability to jump back and forth in a query no longer in 2.2

neo4j,cypher
A query I used to run in 2.1.x which worked fine has stopped working in 2.2.x Example Create objects: Create (n:Test {val:"n"})-[:CONNECTION]->(o:Test {val:"o"})-[:CONNECTION]->(p:Test {val:"p"}) In 2.1.8, if I run this query (note the order of the MATCH clause): MATCH (n:Test)-[:CONNECTION*1..2]-(p:Test),(p)-[:CONNECTION*1..2]-(o:Test) Where(n.val = 'n') and(o.val = 'o') and(p.val = 'p') return...

Cypher/Neo4j: How to match nodes related to n “consecutive” nodes

date,neo4j,cypher,graph-databases
I'm trying to match listing availabilities in my graph (Airbnb-like). The graph has 1 node per date, and consecutive days are linked by a NEXT_DAY edge. Listings are linked to day nodes by an AVAILABLE edge (if they are available) I'm trying to write a query which returns all listings...

get common friends between 2 users and all mutual friends between user and common firends using neo4j

neo4j,cypher
Lets assume a,b,c and b,d,e and c,f,g, and a,e,g,h are friends .So get mutual friends b/w a&b: MATCH (me:User {username:'a'}) -[r:FRIENDS]-(mutualfriends) -[r:FRIENDS]- (u:User {username:'b'}) RETURn mutualfriends Now how to get all common friends from above and user 'a' ? Also can we do all this in one query ?I really...

Merging nodes with the same data using Neo4j

merge,neo4j,cypher,nodes,graph-databases
Here is what I want to do: Connect users to the videos they watch like user -> video in a social graph or network type of graph. How I did it: LOAD CSV WITH HEADERS FROM 'asdfjkl;' AS line CREATE (u {user: line.user }) - [:VIEW] -> (v {video: line.video})...

Large Neo4j graph not showing up

database,graph,neo4j,cypher,graph-databases
I created a large neo4j graph connecting users to the videos they watch like user -> video in a social graph or network type of graph. There are about 9000 user nodes and 20000 video nodes. If I try: MATCH (u)-[:VIEW]->(v) RETURN u,v The graph says "Displaying 300000 nodes, 0...

Neo4j Aggregate Multiple Lines into a Map

neo4j,cypher,aggregate
I have the following Cypher script: MATCH (sy:SchoolYear)<-[:TERM_OF*]-()<-[:DAY_OF]-(d:Day) WHERE sy.year = 2015 OPTIONAL MATCH (d)<-[:START]-(e:Enrollment)-[:AT]->(s:School) RETURN d.date, s.abbreviation, count(e) ORDER BY d.date This gives me all of the dates in the range that I want and returns number of students that have enrolled for each school for that date, or...

Why is the sort order lost when returning a collection via the REST API with resultDataContents=graph

neo4j,cypher
For the following data: create (a:Attendee {name:'luanne'}); create (a:Attendee {name:'adam'}); create (a:Attendee {name:'christoph'}); create (a:Attendee {name:'vince'}); create (a:Attendee {name:'michal'}); this query MATCH p=(n:Attendee)-[r*0..1]-(m) WITH p order by head(nodes(p)).name return collect(distinct(p)) when executed via the shell return paths of length one, ordered by the name of the first node in the...

How to query collection using cypher in neo4j?

java,graph,neo4j,cypher,spring-data-neo4j
I have one node in neo4j whose structure looks like: { "nodeId": 32, "id": "0290cf88-3345-4c30-8e5f-7ce0cb3f0b6b", "type": "User", "name": "Mahendra", "index": 0, "data": "This is sample user", "description": null, "contentBlocks": [], "icon": null, "createdOn": null, "modifiedOn": null, "properties": { "displayName": "Mahendra", "lastName": "Kawde" }, "tags": [ "tag1", "tag2" ], "categories": null...

how to create relationships in loop in neo4j

neo4j,cypher
I am trying to create friend relationship to all the ids in the list but I am getting an error: Node already exists with label User and property "id"=[2] Neo.ClientError.Schema.ConstraintViolation Basically these ids already exist and I just want to create friend relationship to multiple ids at once using for-each.How...

“scala.MatchError” on Cypher CREATE query

php,neo4j,cypher
I'm trying to insert a few nodes and edges into a Neo4j graph using Cypher statements. Upon executing the query, I get a not very meaningful scala.MatchError response from the server. I'm using Neo4j in version 2.2.0. This is my Cypher query (note that it's originally part of a much...

connect nodes with NEXT replation by date

neo4j,cypher,relationship
i have this sample graph: http://console.neo4j.org/?id=mginka and i'm trying to find a Cypher code,that will connect all the hits nodes of each session by the date_time field with [NEXT] relation – hits from different sessions shouldn't be connected.. thanks, Lior...

AllShortestPaths missing relationships

neo4j,cypher
I've been using all shortest paths to retrieve all relationships within a certain number of relations from a root node. As an example, the following queries are run against the standard Matrix themed graph. Query 1: MATCH p = allshortestPaths((n:Crew)-[r*0..3]-(m)) WHERE n.name = 'Neo' UNWIND relationships(p) AS rels RETURN COLLECT(DISTINCT...

Neo4J cypher query for “inherited” terms

neo4j,cypher
Using the community edition of neo4j v2.1.7, I am creating nodes to represent licenses. Each license has terms and can "inherit" terms from another license. Terms local to a license shadow the same terms in the inherited license. I am attempting to write a cypher query that will match on...

neo4j select nodes that have at least n relations

neo4j,cypher
I'm trying to build a cypher query that select people that live in a city and countries that those cities belong to. this is what I have at them moment: MATCH (p:Person)-[r:LiveIn]-(city:City) WHERE s.name= "a" OR s.name= "b" OR ... MATCH (city)-[:IsIn]-(country:Country) RETURN city,country,person but what I really want to...

neo4j cypher return structured map

collections,neo4j,cypher
Lets say, we have a database with (:TvShow)-[:contain]->(:Season)-[:contain]->(:Episode) Now lets say, one wants to query the database for a specific :TvShow and get a result shaped this way : {tvshow : //The tvShow node// , seasons: [ {season: //Season node// , episodes: [//episode node//]}]} For exemple: if we have OneShow...

Neo4j Cypher: Group nodes by the relation to another node

neo4j,cypher
Having a graph like post-->category, how can I get one post per category? i.e.: Having Post A1 --> Category A Post A2 --> Category A Post B1 --> Category B Post B2 --> Category B Post B3 --> Category B Post C1 --> Category C I should get Post A2,...

Filtering out nodes based on outgoing relationship in Cypher query (Similar to SQL outer join)

neo4j,cypher
I have a simple database with three types of nodes (t:transcripts, f:protein families and g:genes. There are two types of relationships, PFAM_MRNA (t)-[r]->(f) and Parent (t)-[p]->(g). (g:Gene{Name:'g1'})<-[p:Parent]-(t:transcript{Name:'t1'}) (g:Gene{Name:'g1'})<-[p:Parent]-(t:transcript{Name:'t2'}) (g:Gene{Name:'g2'})<-[p:Parent]-(t:transcript{Name:'t3'}) (g:Gene{Name:'g3'})<-[p:Parent]-(t:transcript{Name:'t4'}) (g:Gene{Name:'g4'})<-[p:Parent]-(t:transcript{Name:'t5'})...

Limit the results of a union cypher query

neo4j,cypher
Let's say we have the example query from the documentation: MATCH (n:Actor) RETURN n.name AS name UNION MATCH (n:Movie) RETURN n.title AS name I know that if I do that: MATCH (n:Actor) RETURN n.name AS name LIMIT 5 UNION MATCH (n:Movie) RETURN n.title AS name LIMIT 5 I can reduce...

Cyper - odd error when creating relationship

neo4j,cypher
I've got the following query, which responds with the very cryptic error message of "Invalid input 'H': expected 'i/I' (line 2, column 2)" Here's the query: CREATE UNIQUE (c:AccountCharge)-[:ACCOUNT_CHARGED]->(a:Account) WHERE (a.ID = "a7f7def6-8f2b-4b21-bfac-dab2f6e6eaae") AND (c.ID = "666b1865-e29d-455b-abb0-50d679952543") Both the nodes exist, and I can't see where there's a break anywhere,...

neo4j load csv - some part doesnt work

neo4j,cypher,load-csv
i have a problem with import from csv. i'm running the following in the shell, and the last part (MERGE (e1)-[:NEXT]->(hit)))) never happens. little frustrating... Each session has x hits. I want to find the last hit of inserted session, and connect it with new hit by a NEXT relation...

Neo4j: Supply cypher parameters in web interface

neo4j,cypher
Is it possible to pass parameters along with a cypher query via Neo4j's web interface or shell? For example, is it possible to get Neo4j's web interface to execute this statement? return {test}; Running this statement in the web interface results in an error: Expected a parameter named test Neo.ClientError.Statement.ParameterMissing...

Neo4j - don't know how to improve cypher query

neo4j,cypher
I have this query returning very fast, 0.5 seconds and returning all 303 records expected. Note: "Woka" here means "Book". MATCH (p:Publisher)-[r:PUBLISHED]->(w:Woka)<-[s:AUTHORED]-(a:Author), (l:Language)-[t:USED]->(w:Woka)-[u:INCLUDED]->(b:Bisac) WHERE (a.author_name = 'Camus, Albert') RETURN w.woka_id as woka_id, p.publisher_name as publisher_name, w.woka_title as woka_title, a.author_name as author_name, l.language_name as language_name, b.bisac_code as bisac_code, b.bisac_value as bisac_value...

What is the most performant way to create the following MATCH statement and why?

neo4j,cypher
The question: What is the most performant way to create the following MATCH statement and why? The detailed problem: Let's say we have a Place node with a variable amount of properties and need to look up nodes from potentially billions of nodes by it's category. I'm trying to wrap...

Neo4j: Relationship direction cypher

neo4j,cypher,relationship
For the cypher - match (m)-[r]-(n) where m.name = 'XYZ' return n.name, type(r), m.name n.name type(r) m.name XYZ belongs_to Ordering Status XYZ runs_on_queue inbound XYZ runs_on_db DBxc In this case, Ordering Status is a business service that "owns" XYZ & the relation is defined as follows: CREATE (XYZ)-[:belongs_to]->(Order) Type(r) only...

Extract value from property array in Neo4j

neo4j,cypher
I have something like this: MATCH (a)-[rel]->(b), x WHERE x.id = rel.allIds.contains(5) RETURN x where the rel.allIds is an array of numbers. How can I make the contains query in cypher? Note: I'm using Neo4j 2.1.5 version...

fast way to execute multiple CREATE statements

java,neo4j,cypher
I access a neo4J database via Java and I want to create 1,3 million nodes. Therefore I create 1,3 million "CREATE" statements. As I figured out, the query is way too long. I only can execute ~100 CREATE statements per query - otherwise the query fails: Client client; WebResource cypher;...

In a single query how to get feeds and also the information about which feeds have been liked by the logged in user

neo4j,cypher
MATCH (f:Feed) WHERE f.feedType = 'sports' RETURN f order by f.timeAdded desc SKIP 4 LIMIT 10 I have User node and Feed node. I want to retrieve feeds related to sports with pagination. For that I have written the query as above. But with this I also need to know...

How to get total number of db-hits from Cypher query within a Java code?

neo4j,cypher,query-execution-plans
I am trying to get total number of db-hits from my Cypher query. For some reason I always get 0 when calling this: String query = "PROFILE MATCH (a)-[r]-(b)-[p]-(c)-[q]-(a) RETURN a,b,c"; Result result = database.execute(query); while (result.hasNext()) { result.next(); } System.out.println(result.getExecutionPlanDescription().getProfilerStatistics().getDbHits()); The database seems to be ok. Is there something...

number of connected nodes to specific nodes in a path

neo4j,cypher
I have a cypher query (below). It works but I was wondering if there's a more elegant way to write this. Based on a given starting node, the query tries to: Find the following pattern/motif: (inputko)-->(:cpd)-->(ko2:ko)-->(:cpd)-->(ko3:ko). Foreach the motifs/patterns found, find connected nodes with labels contigs, for the following nodes...

create relationship and merge node in loop in neo4j

neo4j,cypher
I am trying to create a relationship in loop from both top list and bottom list .I am trying to connect the top loop with the bottom loop .I really appreciate any help.Thanks. UNWIND [{id:"1",name:"b1",year:"2010"}, {id:"2",name:"d1",year:"2011"}, {id:"3",name:"e1",year:"2013"}] as user MERGE (u:User {id: user.id, name: user.name,year:user.year}) UNWIND [{id:"21",name:"b",year:"2010"}, {id:"41",name:"d",year:"2011"}, {id:"51",name:"e",year:"2013"}] as...

Need help converting Neo4j Cypher request to JPQL

jpa,neo4j,cypher,jpql
I have that Neo4j Cypher request that I need to convert to JPQL: MATCH (p:Person)-[:worksForOrganisation]-> (:Organisation)-[*0..2]->(:Organisation) -[:possessesResource|:accessesResource|:supportsResource]->(:Software) <-[:categoryContains]-(c:ResourceCategory) WHERE id(p)=({personId}) RETURN c This request starts from a unique Person with identifier personId. We know that this person works for one (in rare cases, many) Organisations. We know that each organisation...

Set label after return with limit

neo4j,cypher
MATCH (n:User) SET n: Influence RETURN n ORDER BY n.Followers DESC LIMIT 10 This code will first set a new label for all the User nodes and then return the first 10. What i'm trying to do is to set a new label just for the 10 first returned nodes....

Neo4J: cypher for relations

neo4j,cypher,relationship
I have a hierarchy in the following format: Application.A <-[:belongs_to {roles:instance}]-Instance.A1-[:depends_on {roles:host}]-> Host.vm1 implying Application A has an instance A1 which is running on Host vm1 with the relation "belongs_to" and "depends_on". Instance.A1-[:depends_on {roles:instance}]-> Database db1 <-[:belongs_to]-Instance.dbNode1-[:depends_on {roles:host}]-> Host.vm2 implying instance A1 of Application A depends on Database db1 that...

case insensitive search for labels

neo4j,cypher
Why this code doesn't work MATCH (n) WHERE labels(n)=~ '(?i).*SUBSTRING.*' RETURN distinct labels(n) Type mismatch: expected String but was Collection (line 1, column 17 (offset: 16)) But this does match n-[r]-() where type(r)=~ '(?i).*SUBSTRING.*' return distinct type(r) ...

Neo4j import csv to database

import,neo4j,cypher,load-csv
I want to import Publications from csv to neo4j. And make Query which will select all authors which are authors of publication or at least one author. I have csv file in format Author,Publication Sanjeev Saxena,Parallel Integer Sorting and Simulation Amongst CRCW Models. Hans-Ulrich Simon,Pattern Matching in Trees and Nets....

Can't use EXISTS in a cypher query

spring,maven,neo4j,cypher,spring-data-neo4j
I'm working on a java project using spring-data and neo4j. I tried to write a cypher query using the predicate EXISTS but I have an error telling me "nested exception is Unknown function 'EXISTS'". I have the following pom.xml : <properties> <aspectj.version>1.7.4</aspectj.version> <js.basedir>src/main/webapp/js</js.basedir> <jsonpath.version>0.9.1</jsonpath.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>...

Renaming index in neo4j

neo4j,cypher
In neo4j I have created an index on the property name, but I want to rename the index. Currently I access the node, delete the old index and set the new index name. Is there any method to do this without such a deletion?...

Neo4j filtering nodes with only one type of relationship

neo4j,cypher
I'm new with neo4j and I'm stuck in this exercise. I have to find the names and cities of the students who only have friends in their city. The graph is something like this: The name of the relationship is "FRIEND_OF", and the color represents the city. Thanks so much....

NEO4J: Parent Child type filtering where they Share the same Label

neo4j,cypher
I am trying to work out how to return a result set that contains: Parent/Child type nodes, with the children having the same label as the parent and thus being a valid item in the main results But the Child node should be excluded from the main results if they...

How can I efficiently create unique relationships in Neo4j?

optimization,neo4j,cypher
Following up on my question here, I would like to create a constraint on relationships. That is, I would like there to be multiple nodes that share the same "neighborhood" name, but each uniquely point to a particular city in which they reside. As encouraged in user2194039's answer, I am...

Neo4j: performance issue finding all paths between two nodes with CYPHER

path,neo4j,cypher
I'm using TheMovieDB database downloaded here. It has ~60k nodes and ~100k relationships and I need to find all the paths of a given length k between two nodes a and b with a given name property. Let's say I need to find all the path of lenght 2 between...

Neo4j find nodes with the same properties

graph,neo4j,cypher,nodes
I have a Neo4j graph where each node is a person. Each person has two properties: Name and City. And the relationships are: friend_of and love. I'm trying to get the nodes that have friends ONLY in their same city (A live in Paris, B in Paris, C in Madrid,...

Count duplicated

neo4j,cypher
Imagine that i have a graph in which for every pair of nodes m,n of type Nod1 there can be a node k of type Nod2 that connect them through relationships of type Rel, that is, there can be multiple patterns of the kind p=(m:Nod1)-[r:Rel]-(k:Nod2)-[s:Rel]-(n:Nod1). For a given node m...

Cypher: Graph a nodes's connections 3 deep

neo4j,cypher
given a node, I want to use D3 to graph it, and it's neighborhood 3 deep. The best strategy I can come up with is: Query1: MATCH (n)-[r]-(m) WHERE id(n) IN [501] RETURN n, r, m Then from the results, in my app, collect all of m's id's, put those...

Neo4j - Cypher statement to build relationships took near half of day to complete with error “Self-suppression not permitted”

neo4j,cypher
Usually I am building relationships between nodes while loading from CSV files. Here is a statement written cypher I used this time to build relationships between nodes. The Language nodes are 39K and the Description nodes are 2M. MATCH (d:Description),(l:Language) > WHERE d.description_language = l.language_name > CREATE (d)-[r:HAS_LANGUAGE]->(l); After a...

Issue with multiple match statements, results no rows for valid patterns

graph,neo4j,cypher
I am trying to created a graph in Neo4j with Agents and "KNOWS" relationship. Match (a:AGENT {name:'a'}) Match (e:AGENT {name:'e'}) Match d1 = (a) -[r1:KNOWS]-> (e) Match d2 = (a) -[r1:KNOWS]-> (x) -[r2:KNOWS]-> (e) Return d2 Given: d1 ran independently returns no rows. d2 ran independently returns a valid result...

Neo4j Return Top Level Nodes in Tree

neo4j,cypher
I have the following data in Neo4j: CREATE (t1:T {start:1, end:8}) CREATE (t2:T {start:1, end:4}) CREATE (t3:T {start:1, end:2}) CREATE (t4:T {start:3, end:4}) CREATE (t5:T {start:5, end:6}) CREATE (t6:T {start:7, end:8}) CREATE (t2)-[r1:T_OF]->(t1) CREATE (t3)-[r2:T_OF]->(t2) CREATE (t4)-[r3:T_OF]->(t2) CREATE (t5)-[r4:T_OF]->(t1) CREATE (t6)-[r5:T_OF]->(t1) This creates a tree with start and end values,...

MATCH on GUID in Neo4js

neo4j,cypher
I imported a CSV dump from MS SQL into Neo4j. One of the nodes has a GUID as a primary key, but when I try to do a match, I get no results although the row is there. I tried the following query: MATCH (n:User) where n.UserId = "006cbcc9-7452-4bd3-a1da-c9f96fb15ff9" RETURN...

Neo4j 2.2.2 and wrong Cypher query

neo4j,cypher,spring-data-neo4j,graph-databases
In continue to this question Neo4j how to delete nodes recursively from some start node I have moved to Neo4j 2.2.2 and now have a problem with one Cypher query that works fine on a previous Neo4j 2.1.7 I use Spring Data Neo4J: @Query("MATCH (d:Decision) WHERE id(d) IN {decisionsIds} WITH...

get difference between field values and sum in neo4j

neo4j,cypher
How can I get difference between 2 fields: r.rating_val and rw.rating_val and sum of these fields using neo4j query?I really appreciate any help. MATCH (a:user{id:"1"})-[r:`rating`]->(b), (w:user{id:"3"})-[rw:`rating`]->(b) RETURN DISTINCT b,r.rating_val ,rw.rating_val ...

neo4j return root node once, and all relationships and end-nodes in json

neo4j,cypher
I'm trying to make a html view of everything known about a node. So, if i were to select that node n and RETURN n, i'd get a json object with n: { stuff ... }, and if i also return its relationships and connected nodes RETURN n,r,n2, now i...

Neo4j: using 'order by' and 'limit' with subqueries

neo4j,cypher
I have a data model that's a tree structure with a max depth of 3. For example: (a) ... first level root node / | \ / | \ (b) (b) (b) ... [0..n] number of second depth nodes / | | / | | (c) (c) (c) ... [0..n]...

Get only the nodes related with bidirectional relatioship

graph,neo4j,cypher,nodes,relationship
I have a neo4j graph where A-[r:LOVE]->B and B-[r:LOVE]->A. I'm trying to get all the nodes with that bidirectional relatioship (some nodes for example C-[r:LOVE]->B but B not love C) and I must get them only 1 time (i don't want to get them duplicated) and ordered by name. I'm...

Neo4j: Why are paths of length 0 not returned?

neo4j,cypher
Imagine a simple scenario where a Company has Products, and this data: (c:Company {name: 'Uber'})-[:has_product]->(p:Product {name: 'Uber App'}) I would expect this query match (c:Company)-[:has_product*0..1]->(p:Product) return c.name, p.name; to return Uber, null Uber, Uber App since the path can be of length 0. However, it returns only Uber, Uber App...

Find the nodes with the most mutual connecting nodes?

neo4j,cypher
I'm working with a data set that contains customers, their purchases and the businesses they purchased from, and I'm trying to determine which businesses share the highest number of mutual customers. Ideally the output would be a table that lists the connected businesses and the number of mutual customers. I.e.:...

neo4j cypher Avoid repetion of paths

neo4j,cypher
I have the following query and I want to avoid repetions of the paths(simetric too). MATCH (a:PERSON)-[:LIKES]->(b:PERSON)-[:LIKES]->(a) return a,b I have try DISTINCT keyword but I get and syntax error. Im looking for something like (but fails too): MATCH path=(a:PERSON)-[:LIKES]->(b:PERSON)-[:LIKES]->(a) where DISTINCT(path) return a,b ...

Conditional sum in Neo4j Cypher query

neo4j,cypher
I have a Neo4j database of bank accounts and their incoming transfers. Each transfer occurs at some hour. There are 24 hourNodes representing each different hour (1,2,...,24). I need to know the total money transferred to each account for each hour, like this (yes, I really need 25 columns in...

Return node.name if node2.parameter = 0

neo4j,cypher
When you give someone x something y for some price for ever - it's called "sell". But when you give someone x something y for some price for some time - it's called "rent". And when it's operation have no cost it's called "present". I would like to use neo4j...

order by when some properties contain arrays

neo4j,cypher
I have a database where the same type of node, lets say person, may have either a single string value for a given property or an array of string values. I want to be able to conduct a search and then order results by this property. When attempting that I...

Neo4j Agreggation Subtraction Nodes and propierties

neo4j,cypher,nodes
I'm starting with Neo4j and using graphs, and i'm trying to get the following: I have to find the subtraction(difference) between the number of users (each user is a node) and the number of differents names they have. I have 16 nodes, and each one has his own name (name...

Cypher match exactly by properties

neo4j,cypher
Say I have a node in the database with label L and multiple random properties A=B, C=D, etc. I want to merge another node in the database also with label L but only has the properties A=B. With current Cypher, I could just do a simple: merge (node:L {A:B}) return...

Request for help wirting Cypher query through R-neo4j

r,neo4j,cypher,r-neo4j
I just started programming in R, neo4j and R-neo4j so please be indulgent if my question is trivial. I have created following database (please confer the attached photo) [1] using R-neo4j and the following R Project code [2]. The database contains the outcome of computer game matches between four players....

Why is parameterized Cypher query is taking longer time compared to unparameterized query when using a default planner

performance,neo4j,cypher
I am using neo4j-2.2.1 and using Transactional Cypher Restful Endpoint to query. I am trying to match email nodes using the following query match (e:Email) where e.email in ['[email protected]'] return count(e); The email property in Email node has a unique constraint on it and therefore has a index built automatically...

how to create relationship and merge/create new node in loop in neo4j

neo4j,cypher
I am trying to create friend relationship to all the ids in the list but I am getting an error: y already declared (line 2, column 41 (offset: 64)) "Merge (y:User{id:"21",name:"b"}) Merge (y:User{id:"41",name:"d"}) Merge (y:User{id:"51",name:"e"}) " ^ Neo.ClientError.Statement.InvalidSyntax I am trying to create a new user with id,name,year and also...

neo4j get nodes where first letter of name is some letter

neo4j,cypher
I'm trying to get all nodes whose name starts with an "A" match n where substring(n.name, 0,1) = "a" return n returns zero results. What is the right way to do this?...

How do I calculate all the relationship properties with py2neo or cypher query language

neo4j,cypher,py2neo
The model is for recording all the browse history How could I summation/average/find_max/find_min for all the pages browse to page 2 The expected answers are summation all the browsed time to page2 : 100+200+300+500 find_max browse time to page2 : 500 find_min browse time to page2 : 100 average browse...

Filtering on node property in long distance path

neo4j,cypher
Starting from an item recommended by people, is there a way to filter on a person property, such as age, while traversing at long distance friendship relationships? For instance in the following cypher query, I'd like to only traverse nodes of person +18y, not just filtering on p's age. MATCH...

How to get complete subgraph with direction at Nth level starting at Node M in Neo4j

java,neo4j,cypher
I asked this question How to get subgraph a while back and found while it does give me all nodes and relationships at the Nth level, the answers assume the direction of the relationships either fan out from the starting node or converge to the node. What I am looking...

Symbols within a Neo4j case-insensitive regex

regex,neo4j,cypher
I'm storing e-mail addresses within some user nodes that I'm trying to match against, however the (?i) case-insensitive option doesn't appear to work when a + is added in the mail address. I use these to test, for example [email protected] Setting up test nodes: CREATE (uWithoutSymbol:USER { email: '[email protected]' })...

neo4j specify data-type during import from csv

types,neo4j,cypher,load-csv
is there a way to tell the neo4j the type of the value when importing? for example, does the neo4j knows if "2015-0104T10:33:44" is a date or string? thanks!...

Grab only one out of several node labels

neo4j,cypher
if I have a node with more than one label - how can I receive a selected label of that collection, lets say only the 2nd or 3rd? The node schema is (g:Group:Group1:Group2) I can grab the first maybe with MATCH (g:Group) WHERE LENGTH(LABELS(g)) = 1 return labels(g); When I...

Neo4j : how to match nodes that have a common value in a property array

neo4j,cypher
I have nodes with an "id" property array: node 1: {id:[1,2,3]} node 2: {id:[3,4,5]} node 4: {id:[6,7,8]} I want a query to match the node pairs that have at least one common value in the ID property array; for example the query I'm looking for would return only node 1,...

Find node having two distinct relationship in Cypher

graph,neo4j,cypher,relationship
I am a newbie in Cypher. I am trying to find a query which will returns nodes having more than one relationship to other nodes. Please refer to http://neo4j.com/docs/snapshot/images/cypher-match-graph.svg for the structure. I am trying to find the person who has acted in some movie(s) and also a father. When...

Cypher - atomic insert if node is absent

neo4j,match,case,cypher
I would like to write a single Cypher statement that tests for the existence of a path, adding it if the part is not present. Consider path (:A)-[:REL]->(:B{id:123}), then the existence of the path can be tested by OPTIONAL MATCH p = (:A)-[:REL]->(:B{id:123}) RETURN CASE COUNT(p) WHEN 0 THEN false...

How do I count all the other nodes related to a specific node

neo4j,cypher,py2neo
The path is representing for users' browse history. The upper path means there's one user who has browsed page A -> page B -> page C The lower path means, one user browsed page X-> page Y -> page B -> page C For example, If I want to calculate...

Declare a unique constraint for Neo4j relationships dependent on direction (ideally with py2neo)

python,neo4j,cypher,py2neo
Is there an alternative to py2neo's create_unique method for relationships that takes direction into account? Such that uniqueness === same nodes, same label, and same direction? A solution for Py2neo would be ideal, but I wouldn't be opposed to switching to a more complete driver if there is one. EDIT:...

set propery depending on a condition in a cypher request

neo4j,cypher
I'm working on a cypher request but I do not understand how I can set a property depending on a condition. My current request is like the following : "MATCH (p:Picto{uuid : {pictoUuid}}) OPTIONAL MATCH (p)-[:PICTO_OF]->(e:Element) SET p.deleted = true, e.deleted = true" What I want to do is set...

Labels on Nodes and Relationships from a CSV file

csv,neo4j,load,label,cypher
I have problem when i want to add a label on a Node or to a Relatioship. I do this in Neo4j with Cypher: LOAD CSV WITH HEADERS FROM "file:c:/Users/Test/test.csv" AS line CREATE (n:line.FROM) and i get this error: Invalid input '.': expected an identifier character, whitespace, NodeLabel, a property...

drawing connecting nodes where some number of connections occurs

neo4j,cypher
in neo4j, I'm graphing all nodes that have > x number of connections of relationship r with the following query: match (c:Company)-[r:founder]-(x) with c, count(r) as count where count > 3 return c The above code outputs a graph visualization of company nodes only. If I try to return all...

Neo4j - how to improve queries response time?

neo4j,cypher
I have a query returning in 449824 ms. The result set has 44 rows. This is the query: $ match (w:Woka) where (w.woka_title =~ '.Benedictions.') return w.woka_title; Here are the relevant indexes: ON :Woka(author_id) ONLINE ON :Woka(publisher_id) ONLINE ON :Woka(language_id) ONLINE ON :Woka(woka_title) ONLINE ON :Woka(woka_id) ONLINE This is the...

How do I see if DELETE was successful om Neo4j via REST API?

neo4j,cypher
How do I see if DELETE was successful om Neo4j via REST API ? Here is my query. MATCH (from_user:User),(to_user:User) WHERE from_user.id = '522fed61e4b0a1f88d599ae0' AND to_user.id = '52b9f410e4b03902bd21629e' MATCH from_user-[r]->to_user DELETE r via REST I get following response regardless of whether anything was deleted or not. { "results": [ {...

Neo4j Cypher - How to Count Multiple Property Values With Cypher Efficiently And Paginate Properly

neo4j,cypher
I am struggling to get the proper cypher that is both efficient and allows pagination through skip and limit. Here is the simple scenario: I have the related nodes (company)<-[A]-(set)<-[B]-(job) where there are multiple instances of (set) with distinct (job) instances related to them. The (job) nodes have a specific...

Find all relationship disjoint longest paths in cypher/traversal API ordered by size

neo4j,cypher
I have an algorithm that I want to implement that finds the longest path/s in a graph. Then finds the next longest path/s that do not have any relationships in common with the previous path/s and so forth until the entire graph is represented as disjoint paths. They are disjoint...

Find last node in unknown amount of relationships

neo4j,cypher
I can find last node like this MATCH p=(a)-->(b)-->(c) WHERE a.name='Object' AND c:Prime RETURN c But how i would find last node if i don't know how many relationships -->()-->() between two nodes? I am trying to find last Node name by the Lable name. Last node doesn't have any...

Obtain node property values in an array

neo4j,cypher
Can I return a node property values in an array? Say I create the following node in neo4j: CREATE (p:Person {name:'Ernesto', gender:'male', town:'Cham'}) I can produce the keys by using: MATCH (p:Person {name: 'Ernesto'} ) RETURN keys(p) will produce: [name, gender, town] what is the right method for obtaining: ['Ernesto',...

Global match regular expression with Neo4j Cypher query

regex,neo4j,cypher
I am searching in Neo4j using a regular expression. I would like this search to be global. As it stands, the search will only find words that start with inputted letters in the regular expression: MATCH (a) WHERE a.name =~ '(?i)bob.+' RETURN a.name So it will find the name Bob...

load csv in neo4j got java.lang.OutOfMemoryError: GC overhead limit exceeded exception

neo4j,cypher
I tried to load csv data into embedded neo4j database(v2.1.7、on windows). The csv file has 1,000,000 rows(1 Million). And data model is simple too. just as following: csv data "num1","num2","datatime" "13931345724","18409958023","2014-12-31 12:00:00" "13931345724","13710622859","2014-12-31 12:00:00" "13931345724","18919875049","2014-12-31 12:00:00" "13931345724","13460873081","2014-12-31 12:00:00" ... loading cypher sql USING PERIODIC COMMIT 5000 LOAD CSV FROM 'file:C:/tmpFiles/calls100w.csv'...

Neo4j - querying N items per group

graph,neo4j,cypher,greatest-n-per-group,graph-databases
The following is my query: MATCH (u:User{id:1})-[r:FOLLOWS]->(p:Publisher)<-[:PUBLISHED]-(i:Item)-[:TAGGED]->(t:Tag)<-[f:FOLLOWS]-u RETURN a, count(t) ORDER BY count(k) DESC LIMIT 100 So User can follow Publisher and a Tag. The query find the items, that user may like by counting matching tags. Suppose there two properties, MIN and MAX, on relationship u-r->p. These properties specify,...

Deserialize Json from Neo4J 2.2.2

c#,vb.net,cypher,neo4jclient
I´m using the Neo4J version 2.2.2. When the Neo4jClient try to deserialize the following json (Mode Projection) we receive the following message: Neo4j returned a valid response, however Neo4jClient was unable to deserialize into the object structure you supplied. First, try and review the exception below to work out what...

Neo4j cypher query is too slow(too many dbhits) in bidirectional relationship

neo4j,cypher
Having the flowing data model: (Phone{phoneNumber})-[:CALL]-(Phone{phoneNumber}) (Person{personId})-[:KEEP]-(Phone{personId}) (Case{caseId})-[:INVOLVE]-(Person{personId}) all these three are using bidirectional relationship. And created index on phoneNumber/personId/caseId. User can input one or more strings which maybe represent as phoneNumber/ caseId/personId to query for their relationships(NOT consider direction and relationship depth can be 1 to 4). Here is...

Left join in Neo4j does not seem to work

neo4j,cypher
This is my graph I am trying to make a query that tells me if the connections from a node of type T exist to nodes of type M. I heard that OPTIONAL MATCH is equivalent to SQL Left Join, but it does not include the the missing link. Here...

neo4j optional match and null

neo4j,cypher
Perhaps this approach is wrong but I've built a cypher query using optional matches and collect. If there is data everything is fine, if not, collect returns null for the properties specified. It looks like this is expected as per the docs. Ideally I'd like collect to return an empty...

How do I get the Neo4J primary key back in a query result?

neo4j,cypher
I'm using the rest api, and cypher. How do I get back the primary key when doing a query like this for a node with some id that I have assigned to it? {"statements" : [ {"statement" : "MATCH (n) where n.id = { id } RETURN n", "parameters" :...

neo4j search nodes, relationships contains *string*

neo4j,cypher
Code from LIKE clause in CYPHER Query MATCH (n) WHERE n.name =~ '(?i).*SUBSTRING.*' RETURN n; results in Expected 1 to be a java.lang.String, but it was a java.lang.Long (cause of =~) Is there a way to for strings case insensitive in all possible places?...