Search code examples
javalucenegeospatialorientdbspatial

How to create index for spatial module for OrientDB (2.2.x)?


OrientDB has been upgrade to Spatial Module feature from 2.2.

What is the Java equivalent to create the index for this:

CREATE INDEX ON (geometry-field) SPATIAL ENGINE LUCENE

say, for the example:

ODocument location = new ODocument("OPoint");
location.field("coordinates", Arrays.asList(12.4684635, 41.8914114));

ODocument doc = new ODocument("Restaurant");
doc.field("name","Dar Poeta");
doc.field("location",location);

doc.save();

Ref: http://orientdb.com/docs/2.2/Spatial-Index.html

(I saw some code here: [http://orientdb.com/docs/2.1/Spatial-Index.html] but seems this is for the previous version "spatial index", not "spatial module" from 2.2 onwards.)


Solution

  • You can create the index using OSQL via Java:

        db.command(new OCommandSQL("CREATE INDEX Restaurant.location ON Restaurant(location) SPATIAL ENGINE LUCENE")).execute();