neo4j cypher : unable to create and use an index

2019-04-16 03:38发布

I'd like to create a few indexes on neo4j 2.0 but I can't understand what's wrong here. Starting with a fresh database, my input command looks like

CREATE INDEX ON :user(name);
CREATE INDEX ON :root(root);
CREATE INDEX ON :origin(origin);
CREATE INDEX ON :gender(gender);
create (n1:root {root : 'root'}),(n2:gender {gender : 'female'}),(n3:gender {gender : 'male'}),(n4:origin {origin : 'english (modern)' }),(n5:origin {origin : 'finnish' }),(n6:user {name : 'aaliyah'}),(n7:user {name : 'aapeli'}),(n8:user {name : 'aapo'});

Everything looks fine at this point ( see the output below) but when I try to use the index I get an error:

neo4j-sh (0)$ start n=node:user(name="aapo") return n;
MissingIndexException: Index `user` does not exist

Any idea why this is happening ? Note that creating the nodes before the index doesn't change anything.

Thanks in advance

Output of my first command :

neo4j-sh (0)$ CREATE INDEX ON :user(name);
+-------------------+
| No data returned. |
+-------------------+
Indexes added: 1
235 ms
neo4j-sh (0)$ CREATE INDEX ON :root(root);
+-------------------+
| No data returned. |
+-------------------+
Indexes added: 1
246 ms
neo4j-sh (0)$ CREATE INDEX ON :origin(origin);
+-------------------+
| No data returned. |
+-------------------+
Indexes added: 1
173 ms
neo4j-sh (0)$ CREATE INDEX ON :gender(gender);
+-------------------+
| No data returned. |
+-------------------+
Indexes added: 1
160 ms
neo4j-sh (0)$ create (n1:root {root : 'root'}),(n2:gender {gender : 'female'}),(n3:gender {gender : 'male'}),(n4:origin {origin : 'english (modern)' }),(n5:origin {origin : 'finnish' }),(n6:user {name : 'aaliyah'}),(n7:user {name : 'aapeli'}),(n8:user {name : 'aapo'});
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 8
Properties set: 8
Labels added: 8
1027 ms

1条回答
聊天终结者
2楼-- · 2019-04-16 03:52

The indexes created via Cypher are called Schema indexes, and are not to be used in the START clause. The START clause index lookups are reserved for the legacy indexes that you create via autoindexing or through the non-Cypher APIs.

In order to use the :user index you've created, you can do this:

match n:user
where n.name="aapo"
return n;

Try it out with profile.

查看更多
登录 后发表回答