Reputation: 2878
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?
Upvotes: 5
Views: 3746
Reputation: 15
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>
Docs: CREATE INDEX IF NOT EXISTS
Upvotes: 0
Reputation: 67019
The APOC plugin has an apoc.schema.node.indexExists function for determining whether a specific index exists.
Upvotes: 4
Reputation: 8833
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)
Upvotes: 5