When creating an index through sql in orientDB, I can set it to automatic by doing:
create index MyClass.my_field on MyClass (my_field) unique
As I add records to the DB, my index gets updated. However, if I create the index with Java by doing the following:
OClass target = db.getMetadata().getSchema().getOrCreateClass("MyClass");
target.createProperty("my_field", OType.STRING);
target.createIndex("MyClass.my_field", OClass.INDEX_TYPE.UNIQUE, "my_field");
db.getMetadata().getSchema().save();
My index is successfully created, but doesn't update automatically. Is there some flag I can set to the index creation to tell it to update as I save new records?
Well, it's not a great solution, but I ended up doing:
String sql = "create index MyClass.my_field on MyClass (my_field) unique"
OCommandSQL createIndex = new OCommandSQL(sql);
Object done = db.command(createIndex).execute(new Object[0]);
and it works. I'm never a fan of writing raw sql in my code though...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With