2013-05-27 12 views
1

從第44頁或Neo4J book,我該如何創建示例數據所需的索引以使查詢起作用?無法在書籍圖表數據庫中使用示例來運行

我已經設置了自動索引中neo4j.properties與上市相關的..._ keys_indexable但是在外殼我總是得到「沒有定義的索引筆者

我又試圖用線沿線的一個錯誤REST接口手動添加索引,刪除並重新導入查詢運行的示例數據,但返回零結果。

START theater=node:venue(name='Theatre Royal'), newcastle=node:city(name='Newcastle'), bard=node:author(lastname='Shakespeare') MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater) <-[:VENUE]-()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]-> (play)<-[:WROTE_PLAY]-(bard) RETURN DISTINCT play.title AS play; 
==> +------+ 
==> | play | 
==> +------+ 
==> +------+ 
==> 0 row 

否則這是一個開箱即用安裝的Neo4j企業1.9

清楚我在這裏失去了一些東西?或者我需要通過Java來做到這一點?

回答

3

非常感謝您提出這個問題,這肯定是一些人遇到的問題,應該在書籍網站上解釋。

Ian和Jim使用Java API創建了數據集,因此他們使用索引框架手動添加節點。

但自動索引工作也很好,一定要設置這兩個屬性,名稱和姓氏作爲node_keys_indexable

你只需要啓用它之前插入數據。

,否則你有重新索引它:

start n=node(*) 
where has(n.name) 
set n.name=n.name 

start n=node(*) 
where has(n.lastname) 
set n.lastname=n.lastname 

那麼你可以使用node_auto_index作爲索引名和它應該工作

​​
0

我修改了例子來使用新的標籤功能。

CREATE (shakespeare:author { firstname: 'William', lastname: 'Shakespeare' }),     (juliusCaesar { title: 'Julius Caesar' }), 
       (shakespeare)-[:WROTE_PLAY { year: 1599 }]->(juliusCaesar), 
       (theTempest { title: 'The Tempest' }), 
       (shakespeare)-[:WROTE_PLAY { year: 1610}]->(theTempest), 
     (rsc { name: 'RSC' }), 
     (production1 { name: 'Julius Caesar' }), 
     (rsc)-[:PRODUCED]->(production1), 
     (production1)-[:PRODUCTION_OF]->(juliusCaesar), 
     (performance1 { date: 20120729 }), 
     (performance1)-[:PERFORMANCE_OF]->(production1), 
     (production2 { name: 'The Tempest' }), 
     (rsc)-[:PRODUCED]->(production2), 
     (production2)-[:PRODUCTION_OF]->(theTempest), 
     (performance2 { date: 20061121 }), 
     (performance2)-[:PERFORMANCE_OF]->(production2), 
     (performance3 { date: 20120730 }), 
     (performance3)-[:PERFORMANCE_OF]->(production1), 
     (billy { name: 'Billy' }), 
     (review { rating: 5, review: 'This was awesome!' }), 
     (billy)-[:WROTE_REVIEW]->(review), 
     (review)-[:RATED]->(performance1), 
     (theatreRoyal:theatre { name: 'Theatre Royal' }), 
     (performance1)-[:VENUE]->(theatreRoyal), 
     (performance2)-[:VENUE]->(theatreRoyal), 
     (performance3)-[:VENUE]->(theatreRoyal), 
     (greyStreet { name: 'Grey Street' }), 
     (theatreRoyal)-[:STREET]->(greyStreet), 
     (newcastle:city { name: 'Newcastle' }), 
     (greyStreet)-[:CITY]->(newcastle), 
     (tyneAndWear { name: 'Tyne and Wear' }), 
     (newcastle)-[:COUNTY]->(tyneAndWear), 
     (england { name: 'England' }), 
     (tyneAndWear)-[:COUNTRY]->(england), 
     (stratford { name: 'Stratford upon Avon' }), 
     (stratford)-[:COUNTRY]->(england), 
     (rsc)-[:BASED_IN]->(stratford), 
     (shakespeare)-[:BORN_IN]->stratford 

查詢

MATCH (theater:theatre), 
     (newcastle:city), 
     (bard:author), 
     (newcastle)<-[:STREET|CITY*1..2]-(theater)<-[:VENUE]-()-[p:PERFORMANCE_OF]->()-[:PRODUCTION_OF]->(play)<-[:WROTE_PLAY]-(bard) 
WHERE theater.name = "Theatre Royal" AND 
      newcastle.name = "Newcastle" AND 
      bard.lastname = "Shakespeare" 
RETURN DISTINCT play AS play,count(p) AS performance_count