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

前端 未结 6 1567
谎友^
谎友^ 2020-12-24 01:27

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.GraphDatabaseS         


        
相关标签:
6条回答
  • 2020-12-24 01:58

    neo4j 3.1 now supports this as a built-in procedure that you can CALL from Cypher:

    CALL db.indexes();
    

    http://neo4j.com/docs/operations-manual/3.1/reference/procedures/

    0 讨论(0)
  • 2020-12-24 02:08
    CALL db.indexes(); 
    

    is deprecated by new SHOW INDEXES as reported in 4.2

    SHOW INDEXES
    
    0 讨论(0)
  • 2020-12-24 02:18

    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
    0 讨论(0)
  • 2020-12-24 02:18

    This doesn't quite answer your question (I +1'd jjaderberg's answer as well.)

    In py2neo there is some functionality for labels: http://book.py2neo.org/en/latest/schema/

    get_index(label) Fetch a list of indexed property keys for a label.

    FYI, in shell you can use the undocumented schema command.

    0 讨论(0)
  • 2020-12-24 02:19

    Well, in Cypher you cannot do that but there's a REST API request, which works.

    You can check it in Terminal.

    All indexes in the database:

    curl http://localhost:7474/db/data/schema/index/
    

    Indexes on a specific label:

    curl http://localhost:7474/db/data/schema/index/User
    
    0 讨论(0)
  • 2020-12-24 02:23

    What about the :schema command? (In the Neo4j shell it's just schema).

    Works like charm for me in Neo4j 2.0.1

    0 讨论(0)
提交回复
热议问题