Here's a full index-removal example coded in Java
(as with your example) and saved to "inmemory"
for you.
This way you can see a working example to learn with by changing steps to see what happens.
Code
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphVertex;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.*;
import org.janusgraph.diskstorage.keycolumnvalue.scan.ScanMetrics;
import org.janusgraph.graphdb.database.management.ManagementSystem;
import java.util.concurrent.ExecutionException;
public class Test {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) throws InterruptedException, ExecutionException {
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "inmemory").open();
// JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
GraphTraversalSource g = janusGraph.traversal();
g.V().drop().iterate();
janusGraph.tx().commit();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
// if (!janusGraphManagement.containsGraphIndex("_id"))
janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
janusGraphManagement.commit();
JanusGraphVertex vertex = janusGraph.addVertex("entity");
vertex.property("_id", "Test1");
janusGraph.tx().commit();
janusGraphManagement = janusGraph.openManagement();
JanusGraphIndex janusGraphIndex = janusGraphManagement.getGraphIndex("_id");
logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
janusGraphManagement.updateIndex(janusGraphIndex, SchemaAction.DISABLE_INDEX).get();
logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
janusGraphManagement.commit();
ManagementSystem.awaitGraphIndexStatus(janusGraph, "_id").status(SchemaStatus.DISABLED).call();
logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
janusGraphManagement = janusGraph.openManagement();
janusGraphIndex = janusGraphManagement.getGraphIndex("_id");
janusGraphManagement.updateIndex(janusGraphIndex, SchemaAction.DISCARD_INDEX).get();
logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
janusGraphManagement.commit();
ManagementSystem.awaitGraphIndexStatus(janusGraph, "_id").status(SchemaStatus.DISCARDED).call();
logger.info("index.getIndexStatus(propertyKey):\t" + janusGraphIndex.getIndexStatus(propertyKey));
janusGraph.close();
}
}
Logs
Log4j2 Output should look like
2023-05-16 08:51:40,344 [INFO] [o.j.d.c.b.ReadConfigurationBuilder.main] :: Set default timestamp provider MICRO
2023-05-16 08:51:40,355 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8564911500-rmt-lap-win201
2023-05-16 08:51:40,364 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40
2023-05-16 08:51:40,399 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled
2023-05-16 08:51:40,403 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-16T13:51:40.403993Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@255990cc
2023-05-16 08:51:40,460 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes
2023-05-16 08:51:40,791 [INFO] [Main.main] :: index.getIndexStatus(propertyKey): ENABLED
2023-05-16 08:51:40,801 [INFO] [Main.main] :: index.getIndexStatus(propertyKey): DISABLED
2023-05-16 08:51:40,919 [INFO] [o.j.g.d.m.GraphIndexStatusWatcher.main] :: All 1 key(s) on index _id have status(es) [DISABLED]
2023-05-16 08:51:40,919 [INFO] [Main.main] :: index.getIndexStatus(propertyKey): DISABLED
2023-05-16 08:51:40,952 [INFO] [o.j.g.o.j.IndexRemoveJob.Thread-3] :: Index _id metrics: success-tx: 4 doc-updates: 0 succeeded: 1
...
2023-05-16 08:51:41,169 [INFO] [o.j.g.d.m.ManagementSystem.Thread-1] :: Index update job successful for [_id]
2023-05-16 08:51:41,175 [INFO] [Main.main] :: index.getIndexStatus(propertyKey): DISCARDED
2023-05-16 08:51:41,178 [INFO] [o.j.g.d.m.GraphIndexStatusWatcher.main] :: All 1 key(s) on index _id have status(es) [DISCARDED]
2023-05-16 08:51:41,178 [INFO] [Main.main] :: index.getIndexStatus(propertyKey): DISCARDED
Process finished with exit code 0