I am trying to find a way to check if a certain index exists in cypher schema indexes. I can find all the indexes by using call db.indexes()
. but how can I check for a specific index?
If you want the index to exist, I would recommend just running the Cypher to create the index. The result being that whether the index existed or not, after the call it is guaranteed to exist.
On the other hand, if you just want the information for display purposes or something, you can use YIELD to continue a cypher from a CALL. For example...
CALL db.indexes() YIELD label, properties WHERE label="Person" RETURN *
For db.indexes, the variables you can yield are description, label, properties, provider, state, type
(you have to yield them by name, YIELD a,b,c,d,e,f
won't work)
The APOC plugin has an apoc.schema.node.indexExists function for determining whether a specific index exists.
true
or false
, but the value of that is meaningless in the real world unless you can make it part of another execution. –
Impatiens In the current Neo4J 5 in 2024, you can use SHOW INDEXES
(or SHOW CONSTRAINTS) and it will present a list
Docs: Managing Indexes Manual
OR, you can just create the desired index or constraint with the "IF NOT EXISTS" clause, and it will add it only if it isn't in place yet.
Example:
CREATE INDEX <index_name> IF NOT EXISTS
FOR (x:<node_label>)
ON x.<property_key>
© 2022 - 2025 — McMap. All rights reserved.