Search code examples
neo4jcypher

How to check if an index exist in neo4j cypher


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?


Solution

  • 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)