4

I was trying to reproduce the shakespeare data set and queries in my local console. I created the nodes and relationships.

neo4j-sh (0)$ START theater=node:venues(theatre = 'Theatre Royal'), newcastle=node:cities(city = 'Newcastle'), bard=node:authors('firstname:William AND lastname:Shakespeare') MATCH (newcastle)<-[:IN*1..4]-(theater)<-[:VENUE]-(performance)-[:PERFORMED]->(play)<-[w:WROTE]-(bard)  WHERE w.date > 1608  RETURN play;
==> MissingIndexException: Index `authors` does not exist

Did not recognized the authors,venues and cities indexes, so I went to add and remove indexes tab and created these indexes. This is the screen dump

neo4j-sh (0)$ index --indexes
==> Node indexes:
==>   venues
==>   cities
==>   authors
==> 
==> Relationship indexes:

But now, the same query has no error but returns nothing. What Am I doing wrong. The syntax to create index from the web console is not that clear. What am I doing wrong?

Nicholas
  • 7,403
  • 10
  • 48
  • 76
user1848018
  • 1,086
  • 1
  • 14
  • 33
  • If these indexes did not exist prior to you creating them, then running the query will return nothing, most likely because there is no reference for these values in the index. – Nicholas Mar 11 '13 at 16:46
  • So sorry, the documentation is not clear. I am using cypher, do i have to index every node that is a theatre into venues index and every city into cities? From the create index tab, the right format is not clear either. – user1848018 Mar 11 '13 at 19:02

1 Answers1

5

When you create a new index, existing nodes are not added to the index automatically. Newly created/edited nodes will be added automatically, but you'll have to handle the existing nodes by hand.

There are three ways for you to get your existing nodes into the index:

  1. Index the nodes manually with Neo4j Shell, using the Index command
  2. Do a useless SET operation to your nodes to force them to be touched (i.e. SET myNode.prop = myNode.prop)
  3. Delete the nodes and recreate them with the same properties and relationships

You can read more about neo4j indexing in the documentation.

ean5533
  • 8,884
  • 3
  • 40
  • 64
  • I am new to this, If I start from scratch with shakespeare dataset, how can I do this in cypher? Is there any way to create and index simultaneously. Thanks for the help – user1848018 Mar 11 '13 at 19:22
  • If you look at the http://console.neo4j.org/?id=shakespeare , graph set up, there is no sign of indexing, how did they do it then? – user1848018 Mar 11 '13 at 19:25
  • 1
    Unfortunately indexes cannot be created, view, or otherwise interacted with through Cypher. Cypher is strictly for querying the data. The database they are using is likely already set up to index the appropriate properties behind the scenes. I suggest you read the [Neo4j reference documentation](http://docs.neo4j.org/chunked/milestone/reference-documentation.html), particularly the [section on indexing](http://docs.neo4j.org/chunked/milestone/indexing.html). – ean5533 Mar 11 '13 at 19:38
  • 2
    But that only works for the automatic index, the indexes used in the book are created manually and the nodes added manually too. The console uses a trick to convert the index name you see into an automatic index name. – Michael Hunger Mar 14 '13 at 12:35