如何检查neo4j中节点属性的模式索引是否已存在? [英] How to check if a schema index already exists for a node's property in neo4j?
本文介绍了如何检查neo4j中节点属性的模式索引是否已存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 IndexDefinition 用于在neo4j中填充给定属性上的索引.
I am using IndexDefinition for populating index over a given property in neo4j.
IndexDefinition indexDefinition = schema.indexFor(DynamicLabel.label("Person")).on("NodeType").create();
问题是当我再次使用索引填充的类似代码执行程序时,出现以下异常.
Problem is when I execute the program again with similar code for Index population, I get following exception.
org.neo4j.kernel.api.exceptions.schema.AlreadyIndexedException: Already indexed :label[0](property[0]).
at org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementContext.checkIndexExistence(DataIntegrityValidatingStatementContext.java:107)
at org.neo4j.kernel.impl.api.DataIntegrityValidatingStatementContext.indexCreate(DataIntegrityValidatingStatementContext.java:78)
我只想检查某个属性的索引是否已经存在,那么以后就不应该进行索引填充了.
I just want to check if an Index for a property is already there, then no subsequent Index population should take place.
推荐答案
为什么在尝试创建标签并获取(正确的)异常之前不检查标签的索引?
why don't you check the Indexes for a Label before trying to create it and getting a (correct) exception?