我正在寻找类似于 MySQL ( SHOW INDEXES ) 的东西。我能够在 Python 中使用 py2neo 获取索引列表
graphDB = neo4j.GraphDatabaseService()
indexes = graphDB.get_indexes(neo4j.Node)
print(format(indexes))
但我想知道是否有办法在 Cypher 中做类似的事情。
还没有。在 Neo4j 2.0 中,引入了更密码友好的索引,您可以发出一些 DDL 命令来创建和删除索引和约束,但从 2.01 开始就是这样(请参阅docs)。在 1.9 中,您根本无法使用 cypher 定义这种类型的模式。
--
例如,在 cypher 之外有很多方法
在neo4j-shell
你可以
index --indexes
schema
schema ls -l :YourLabel
在neo4j-browser
你可以
:schema
:schema ls -l :YourLabel
大多数让您执行密码查询的 API 也将提供查询模式的方法,例如
GraphDatabaseService.schema().getConstraints()
和.getIndexes()
标签模式GraphDatabaseService.index().nodeIndexNames()
对于遗留.relationshipIndexNames()
索引/db/data/schema/
基于标签的架构的端点/db/data/index/node/
和/db/data/index/relationship/
for legacy 索引neo4j 3.1 现在支持将此作为内置程序,您可以从 Cypher 调用:
CALL db.indexes();
http://neo4j.com/docs/operations-manual/3.1/reference/procedures/
:schema
命令呢?(在 Neo4j shell 中只是schema
)。
在 Neo4j 2.0.1 中对我来说就像魅力一样
CALL db.indexes();
4.2 中报告的新 SHOW INDEXES 已弃用
SHOW INDEXES
好吧,在 Cypher 中你不能这样做,但是有一个 REST API 请求,它可以工作。
您可以在终端中检查它。
数据库中的所有索引:
curl http://localhost:7474/db/data/schema/index/
特定标签上的索引:
curl http://localhost:7474/db/data/schema/index/User
这并不能完全回答您的问题(我也为 jjaderberg 的回答 +1。)
在 py2neo 中有一些标签功能:http: //book.py2neo.org/en/latest/schema/
get_index(label)
获取标签的索引属性键列表。
仅供参考,在 shell 中,您可以使用未记录的schema
命令。