Search code examples
gremlinjanusgraph

When indexed, throw Exception during add Vertex


The index has built well;
No Exception Here, and the graphManagement has committed well;

graphManagement.buildIndex("uidIndex", Vertex.class). 
     addKey(graphManagement.getPropertyKey("uid_code")).
     buildCompositeIndex();

i have configured the query.force-index=true
But when I try to add some vertex, using the propertyKey 'uid_code', code is following:

Vertex vertex = g.V().addV(label).
       property(propertyKey, propertyValue).
       next(); 

Exception throwed :

org.janusgraph.core.JanusGraphException: Could not find a suitable index to answer graph query and graph scans are disabled: [()]:VERTEX
    at org.janusgraph.graphdb.transaction.StandardJanusGraphTx$6.execute(StandardJanusGraphTx.java:1283)
    at org.janusgraph.graphdb.transaction.StandardJanusGraphTx$6.execute(StandardJanusGraphTx.java:1150)
    at org.janusgraph.graphdb.query.QueryProcessor$LimitAdjustingIterator.getNewIterator(QueryProcessor.java:209)
    at org.janusgraph.graphdb.query.LimitAdjustingIterator.hasNext(LimitAdjustingIterator.java:68)
    at com.google.common.collect.Iterators$7.computeNext(Iterators.java:650)
    at com.google.common.collect.AbstractIterator.tryToComputeNext(AbstractIterator.java:143)
    at com.google.common.collect.AbstractIterator.hasNext(AbstractIterator.java:138)
    at org.janusgraph.graphdb.query.ResultSetIterator.nextInternal(ResultSetIterator.java:54)
    at org.janusgraph.graphdb.query.ResultSetIterator.<init>(ResultSetIterator.java:44)
    at org.janusgraph.graphdb.query.QueryProcessor.iterator(QueryProcessor.java:68)
    at com.google.common.collect.Iterables$7.iterator(Iterables.java:613)
    at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.lambda$new$0(JanusGraphStep.java:71)
    at org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep.processNextStart(GraphStep.java:142)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.hasNext(AbstractStep.java:143)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.ExpandableStepIterator.next(ExpandableStepIterator.java:50)
    at org.apache.tinkerpop.gremlin.process.traversal.step.map.MapStep.processNextStart(MapStep.java:36)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:128)
    at org.apache.tinkerpop.gremlin.process.traversal.step.util.AbstractStep.next(AbstractStep.java:38)
    at org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal.next(DefaultTraversal.java:200)
    at dataTrans.KfkMsgParser.createMerge(KfkMsgParser.java:742)   

Can someone tell me whether i forget something in document ?
Or
what i can do to fix this problem ?


Solution

  • To add a single vertex, you should invoke addV() directly on the traversal source g:

     String propertyKey = "uid_code";
     Vertex vertex = g.addV(label).
         property(propertyKey, propertyValue).
         next();
    

    When you start the query with g.V().addV(label)..., the traversal attempts to scan all vertices with g.V() and thus the exception is thrown.