无法在图书数据库中获得示例工作

时间:2013-05-27 07:13:07

标签: database graph neo4j

从第44页或Neo4J book,如何创建示例数据所需的索引,以便查询起作用?

我在neo4j.properties中设置了自动索引并列出了相关的... _ keys_indexable但是在shell中我总是得到一个错误,就像'index author not defined'

然后我尝试使用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 enterprise 1.9安装

显然我在这里遗漏了一些东西?或者我需要通过Java做到这一点吗?

2 个答案:

答案 0 :(得分: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作为索引名称,它应该可以工作

START theater=node:node_auto_index(name='Theatre Royal'), 
newcastle=node:node_auto_index(name='Newcastle'), 
bard=node:node_auto_index(lastname='Shakespeare') 

MATCH (newcastle)<-[:STREET|CITY*1..2]-(theater) <-[:VENUE]-
      ()-[:PERFORMANCE_OF]->()-[:PRODUCTION_OF]-> 
      (play)<-[:WROTE_PLAY]-(bard) 

RETURN DISTINCT play.title AS play;

答案 1 :(得分: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