Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - Is there a cypher query syntax to list (show) all indexes in DB?

I'm looking for something similar to the MySQL ( SHOW INDEXES ). I was able to get a list of indexes using py2neo in Python

graphDB = neo4j.GraphDatabaseService() indexes = graphDB.get_indexes(neo4j.Node) print(format(indexes)) 

but I wanted to know if there's a way to do something similar in Cypher.

like image 460
Bryan Mayes Avatar asked Nov 06 '13 00:11

Bryan Mayes


People also ask

What are indexes in Neo4j?

In neo4j you can create index for both property and nodes. Indexing is data structure that helps faster performance on retrieval operation on database. There is special features in neo4j indexing once you create indexing that index will manage itself and keep it up to date whenever changes made on the database.

Can you run Cypher statements on the system database in Neo4j?

You typically use cypher-shell to execute Cypher against a user database, but you can also use it to perform some management tasks against the Neo4j instance by accessing the system database.

What is the syntax for getting all the nodes under specific label in Neo4j?

If you want to get the labels of a specify node, then use labels(node) ; If you only want to get all node labels in neo4j, then use this function instead: call db. labels; , never ever use this query: MATCH n RETURN DISTINCT LABELS(n) . It will do a full table scan, which is very very slow..


1 Answers

Not yet. In Neo4j 2.0 more cypher friendly indexing was introduced and you can issue some DDL commands to create and drop indices and constraints, but as of 2.01 that's it (see docs). In 1.9 you can't define that type of schema with cypher at all.

--

There are many ways outside of cypher, for instance

In neo4j-shell you can

  • list legacy indices with index --indexes
  • list all label indices and constraints with schema
  • list indices and constraints for specific label with schema ls -l :YourLabel

In neo4j-browser you can

  • list all label indices and constraints with :schema
  • list indices and constraints for specific label with :schema ls -l :YourLabel

Most APIs that let you execute cypher queries will also provide ways to query schema, such as

  • Native Java API
    • GraphDatabaseService.schema().getConstraints() and .getIndexes() for label schema
    • GraphDatabaseService.index().nodeIndexNames() and .relationshipIndexNames() for legacy indices
  • REST calls to
    • /db/data/schema/ endpoints for label based schema
    • and to /db/data/index/node/ and /db/data/index/relationship/ for legacy indices
like image 85
jjaderberg Avatar answered Sep 19 '22 22:09

jjaderberg