How Do You Create Indexes In Java? #3768
-
Why is JanusGraph not recognizing the index I've made? [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes I'm currently using a new and empty Cassandra [Docker container] so testing starts from a blank slate. 2023-05-10 13:08:36,511 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:19042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-10 13:08:36,652 [INFO] [c.d.o.d.i.c.DefaultMavenCoordinates.main] :: DataStax Java driver for Apache Cassandra(R) (com.datastax.oss:java-driver-core) version 4.15.0
2023-05-10 13:08:37,447 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-10 13:08:37,967 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/[0:0:0:0:0:0:0:1]:19042, hostId=null, hashCode=323b2632)=null; please provide the correct local DC, or check your contact points
2023-05-10 13:08:39,254 [INFO] [o.j.d.c.b.ReadConfigurationBuilder.main] :: Set default timestamp provider MICRO
2023-05-10 13:08:39,292 [INFO] [o.j.g.i.UniqueInstanceIdRetriever.main] :: Generated unique-instance-id=c0a8563c11216-rmt-lap-win201
2023-05-10 13:08:39,316 [INFO] [c.d.o.d.i.c.ContactPoints.main] :: Contact point localhost:19042 resolves to multiple addresses, will use them all ([localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1])
2023-05-10 13:08:39,365 [INFO] [c.d.o.d.i.c.t.Clock.JanusGraph Session-admin-0] :: Using native clock for microsecond precision
2023-05-10 13:08:39,441 [WARN] [c.d.o.d.i.c.l.h.OptionalLocalDcHelper.JanusGraph Session-admin-0] :: [JanusGraph Session|default] You specified datacenter1 as the local DC, but some contact points are from a different DC: Node(endPoint=localhost/127.0.0.1:19042, hostId=null, hashCode=27f6e3ea)=null; please provide the correct local DC, or check your contact points
2023-05-10 13:08:39,471 [INFO] [o.j.d.c.ExecutorServiceBuilder.main] :: Initiated fixed thread pool of size 40
2023-05-10 13:08:43,405 [INFO] [o.j.g.d.StandardJanusGraph.main] :: Gremlin script evaluation is disabled
2023-05-10 13:08:43,422 [INFO] [o.j.d.l.k.KCVSLog.main] :: Loaded unidentified ReadMarker start time 2023-05-10T18:08:43.422170Z into org.janusgraph.diskstorage.log.kcvs.KCVSLog$MessagePuller@37b52340
2023-05-10 13:08:44,856 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes
2023-05-10 13:08:44,874 [INFO] [Main.main] :: g.V().count().next(): 0
2023-05-10 13:08:44,880 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes
2023-05-10 13:08:44,885 [WARN] [o.j.g.t.StandardJanusGraphTx.main] :: Query requires iterating over all vertices [[]]. For better performance, use indexes
2023-05-10 13:08:44,889 [INFO] [Main.main] :: g.V().count().next(): 0
Process finished with exit code 0 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.JanusGraphManagement;
public class Test {
private static final Logger logger = LogManager.getLogger(Main.class);
public static void main(String[] args) {
JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:19042").open();
JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
if (!janusGraphManagement.containsGraphIndex("_id"))
janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
janusGraphManagement.commit();
GraphTraversalSource g = janusGraph.traversal();
logger.info("g.V().count().next():\t" + g.V().count().next());
g.V().drop().iterate();
logger.info("g.V().count().next():\t" + g.V().count().next());
janusGraph.close();
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
In your case you created an index, but didn't enable it. JanusGraph won't use your index unless you explicitly enable it. Moreover, your queries are not referencing indexed properties. In your case after you created the index:
You should await and enable it (and potentially re-index you current data):
After this your query that utilized the index could look like this:
Check more information on how to create indexes in JanusGraph here: https://docs.janusgraph.org/schema/index-management/index-performance/ |
Beta Was this translation helpful? Give feedback.
In your case you created an index, but didn't enable it. JanusGraph won't use your index unless you explicitly enable it. Moreover, your queries are not referencing indexed properties.
In your case after you created the index:
You should await and enable it (and potentially re-index you current data):