Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-23-2020 03:27 PM
Dear Neo4j Community,
I have a question about Neo4j indexes and could not find the answer anywhere else and hope this is the right category for this as I thought it might be a newbie question. I am using Neo4j Sandbox and the Recommendations dataset.
In the sandbox the syntax
CREATE INDEX Index_Name FOR (n:Label) ON (n.property)
does not seem to work whereas the syntax
CREATE INDEX ON :Label(property)
seems to work. In particular, I created a new label and wanted to introduce an index with
CREATE INDEX Test_index FOR (n:NewLabel) ON (n.name)
which gives me the error
Invalid input 'T': expected whitespace, comment, ON, '=', node labels, MapLiteral, a parameter, a parameter (old syntax), a relationship pattern, ',', FROM GRAPH, CONSTRUCT, LOAD CSV, START, MATCH, UNWIND, MERGE, CREATE UNIQUE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or end of input (line 1, column 14 (offset: 13))
"CREATE INDEX Test_index FOR (n:NewLabel) ON (n.name)"
I really don't know what would be wrong with this as it is just like in the Graph Academy described or am I missing something here? However, if I use
CREATE INDEX ON :NewLabel(name)
this works perfectly fine and creates and index. Because of this it won't let me create named indexes.
Thanks a lot for any help on this.
11-23-2020 05:11 PM
what version of Neo4j is in use?
CREATE INDEX ON :Label(property)
was the old syntax and is still supported.
CREATE INDEX Test_index FOR (n:NewLabel) ON (n.name);
was introduced in 4.0.x. So if you are at a Neo4j version less than 4.0.x then this would not work
11-23-2020 06:16 PM
Hello Dana,
Thank you so much, this explains a lot. I am using the Sandbox from the Neo4j Website and you are right, the version is 3.5.17.
I am also struggling with composite indexes. For my new label I create an index
CREATE INDEX ON :NewLabel(name,bornIn)
with name and bornIn existing for all nodes of NewLabel in case this is relevant.
When I look at the query
PROFILE MATCH (n:NewLabel) WHERE EXISTS(n.name) AND EXISTS(n.bornIn) RETURN n
the query planner does not use the index I created, but does a NodeByLabelScan. However, if I create the index just for name or just for born in the query planer uses that respective index and does a NodeIndexScan.
I cannot make any sense of that, is this maybe also due to the older version of the Sandbox? I could not find anything on that.
Thank you so much for your help.
11-24-2020 05:44 AM
The sandbox uses 3.5. This is from the 3.5 Cypher Manual:
Composite indexes are currently not able to support the exists
predicate.
Elaine
11-26-2020 12:24 AM
Hello Elaine,
Thank you for the help. That explains a lot.
All the sessions of the conference are now available online