问题
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