1

从第 44 页或Neo4J book中,我如何创建示例数据所需的索引,以便查询能够正常工作?

我已经在 neo4j.properties 中设置了自动索引并列出了相关的 ..._keys_indexable 但是在 shell 中我总是得到一个错误,类似于“索引作者未定义”

然后我尝试使用 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 做到这一点?

4

2 回答 2

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;
于 2013-05-27T07:29:46.170 回答
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
于 2013-12-16T21:05:52.003 回答