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?
exists() The function exists() returns true if a match for the given pattern exists in the graph, or if the specified property exists in the node, relationship or map. null is returned if the input argument is null .
In Neo4j, index is a data structure which is used to improve the speed of data retrieval operations in a database. An index can be created over a property on any node that has been given a label. Once an index is created, Neo4j will manage it and keep it up to date whenever the database is changed.
Neo4j will automatically pick up and start using the index once it has been created and brought online. There are multiple index types available: b-tree (deprecated), fulltext, lookup, and text index types.
The WITH clause allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next. It is important to note that WITH affects variables in scope.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With