且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Neo4j 查询已经创建的索引与约束

更新时间:2022-08-15 11:58:16

在Neo4j 2.0之后为cypher语法增加了一些类似于DDL的语法,能够自己创建索引,约束等等。

有如下的方法可以查询到当前图数据库的索引数量:

neo4j-shell 

neo4j-browser

  • 使用::schema 列出所有标签的所有记录

 Neo4j 查询已经创建的索引与约束

  • 使用::schema ls -l :YourLabel列出指定标签的索引与约束

 Neo4j 查询已经创建的索引与约束

大多数APIs都支持使用CQL查询,以下提供两种查询方案

  • Native Java API
public static void main(String[] args) {
        GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(new File("D:\\neo4j\\HelloWorld3"));
        Transaction beginTx = graphDb.beginTx();
        System.out.println("constraint:" + graphDb.schema().getConstraints(DynamicLabel.label("Test")));
        System.out.println("index:" + graphDb.schema().getIndexes(DynamicLabel.label("Test")));
        beginTx.success();
    }

Neo4j 查询已经创建的索引与约束

  • REST calls (这个方法尝试过,行不通)
    • /db/data/schema/ endpoints for label based schema
    • and to /db/data/index/node/ and /db/data/index/relationship/ for legacy indices

以上文内容翻译自***:

http://***.com/questions/19801599/neo4j-is-there-a-cypher-query-syntax-to-list-show-all-indexes-in-db

图片部分是已经试验可以使用

教程结束,感谢阅读。

欢迎转载,但请注明本文链接,谢谢。

 2016-03-30   20:41:44