Java - Check if index already exists neo4j (if clause)

浪尽此生 提交于 2019-12-24 13:35:38

问题


I'm actually building onto the question: How to check if a schema index already exists for a node's property in neo4j?

I can however not find how to do the actual if clause. For example:

label = DynamicLabel.label("Label");
Iterable<IndexDefinition> indexes = schema.getIndexes(label);
for(IndexDefinition index : indexes) {
    if(index.equals(schema.indexFor(label).on("id"))) {
        // index exists on property "id" on label "Label"!
    }
}

This however isn't working!


回答1:


The following snippet should help:

label = DynamicLabel.label("Label");
Iterable<IndexDefinition> indexes = schema.getIndexes(label);
for(IndexDefinition index : indexes) {
    for (String key: index.getPropertyKeys()) {
         if (key.equals("id")) {
              return true; // index for label and property exists
         }
    }
}
return false; // no matching schema index

Please note that in Neo4j 2.0/2.1 each index has only one single property. Multi property indexes are not yet supported - however the API is already designed for that.



来源:https://stackoverflow.com/questions/23443337/java-check-if-index-already-exists-neo4j-if-clause

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!