索引时,在添加顶点时抛出异常

When indexed, throw Exception during add Vertex

索引构建良好;
这里没有例外,并且 graphManagement 的表现很好;

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

我配置了query.force-index=true
但是当我尝试添加一些顶点时,使用 propertyKey 'uid_code', 代码如下:

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

抛出异常:

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.execute(StandardJanusGraphTx.java:1283)
    at org.janusgraph.graphdb.transaction.StandardJanusGraphTx.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.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.iterator(Iterables.java:613)
    at org.janusgraph.graphdb.tinkerpop.optimize.JanusGraphStep.lambda$new[=12=](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)   

谁能告诉我我是否忘记了文档中的内容?
或者
我能做些什么来解决这个问题?

您的索引应该可以使用。

graph.tx().rollback(); //Never create new indexes while a transaction is active
JanusGraphManagement graphManagement = graph.openManagement();
graphManagement.buildIndex("uidIndex", Vertex.class). 
     addKey(graphManagement.getPropertyKey("uid_code")).
     buildCompositeIndex();
graphManagement.commit();

//Wait for the index to become available
ManagementSystem.awaitGraphIndexStatus(graph, "uidIndex").call();

graphManagement = graph.openManagement();
// Use REINDEX to reindex old data and enable the index
// Use ENABLE to simply enable the index
graphManagement.updateIndex(graphManagement.getGraphIndex("uidIndex"), SchemaAction.REINDEX).get();
graphManagement.commit();

您可以在此处查看索引生命周期:https://github.com/JanusGraph/janusgraph/wiki/Indexing

这是索引文档: https://docs.janusgraph.org/latest/indexes.html

要添加单个顶点,您应该直接在遍历源上调用addV() g:

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

当您使用 g.V().addV(label)... 开始查询时,遍历尝试使用 g.V() 扫描所有顶点,因此抛出异常。