1
votes

I am beginning using Neo4j since 2 months. I have created a Neo4j graph and loaded it with 6M cities in it. My Graph store is about 6 gigs. Each city has 4 properties:

  • Name
  • Longitude
  • Latitude
  • Population

These nodes have a label City,

I am trying to run some queries using the Neo4j browser. I have added an index:

CREATE INDEX ON :City(Name)

Now if I run a query looking for a specific name such as the following, then the result comes very fast:

MATCH (n:City)
WHERE n.Name = 'New York'
RETURN n

But when I just want to have the number of cities in the graph, an Unknown Error rises and I can't get the number I am looking for:

MATCH (N:City)
RETURN COUNT(n)

or

MATCH (n:City)
WHERE n.Name =~ 'New.*'
RETURN COUNT(n)

Am I missing something here?

1
Just an ask for the future: Please format your questions to be readable. I took the liberty of editing your question, as in its original form, it was very difficult to see the code.David Makogon
Thanks, it was my first time asking something in here !!!Martin Larivière
You had a typo in this query: MATCH (N:City) RETURN COUNT(n) first you use capital N then lowercase nMichael Hunger
Martin, can you check the JSON result (that is the download arrow just above the query window for an error message and post it here)Michael Hunger
What version are you now using? You should probably upgrade to 2.0.0 final.Michael Hunger

1 Answers

1
votes

Your code for counting the number of cities is correct, the problem is that Cypher is case sensitive, the identifier you want to return must be in the same case as the one you specified in the MATCH clause, your code should read as follow:

MATCH (n:City) 
RETURN count(n)

And for your second code, it should run without any itch, are you sure you label everything properly? At least it should return no rows to indicate that there are no node (in label called City) with a name that start with "New"

MATCH (n:City)
WHERE n.Name =~ "New.*$" 
RETURN count(n)

Don't forget to mind the case when specifying the properties of the nodes in the queries (e.g. "name" is not the same as "Name")