Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if an index exist in neo4j cypher

Tags:

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?

like image 588
Abdullah Al Noman Avatar asked Oct 02 '18 12:10

Abdullah Al Noman


People also ask

Is exist in Neo4j?

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 .

What are indexes in Neo4j?

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.

Does Neo4j support indexing?

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.

WHAT IS WITH clause in Cypher?

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.


2 Answers

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)

like image 112
Tezra Avatar answered Oct 05 '22 16:10

Tezra


The APOC plugin has an apoc.schema.node.indexExists function for determining whether a specific index exists.

like image 32
cybersam Avatar answered Oct 05 '22 16:10

cybersam