gpt4 book ai didi

titan - 在 Titan/Janus 中启用力索引时索引失败

转载 作者:行者123 更新时间:2023-12-01 11:32:10 30 4
gpt4 key购买 nike

我写了一个 JUnit 测试来检查 generate-modern.groovy如果 marko 存在,则绘制图表。
我的小鬼查询是

"g.V().has('name','marko')";



正如您在 generate-modern.groovy 中看到的那样索引已应用于此人的 name 属性的文件。
我后来做了以下

query.force-index=true



dynamodb.properties 中的属性为真阻止整个图形扫描从而强制索引的文件。
但是它给我抛出了以下异常
org.janusgraph.core.JanusGraphException: Could not find a suitable index to answer graph query and graph scans are disabled: [(name = marko)]:VERTEX

上述异常是从以下 StandardJanusGraphTx 类的方法引发的
    @Override
public Iterator<JanusGraphElement> execute(final GraphCentricQuery query, final JointIndexQuery indexQuery, final Object exeInfo, final QueryProfiler profiler) {
Iterator<JanusGraphElement> iter;
if (!indexQuery.isEmpty()) {
List<QueryUtil.IndexCall<Object>> retrievals = new ArrayList<QueryUtil.IndexCall<Object>>();
for (int i = 0; i < indexQuery.size(); i++) {
final JointIndexQuery.Subquery subquery = indexQuery.getQuery(i);

retrievals.add(new QueryUtil.IndexCall<Object>() {
@Override
public Collection<Object> call(int limit) {
final JointIndexQuery.Subquery adjustedQuery = subquery.updateLimit(limit);
try {
return indexCache.get(adjustedQuery, new Callable<List<Object>>() {
@Override
public List<Object> call() throws Exception {
return QueryProfiler.profile(subquery.getProfiler(), adjustedQuery, q -> indexSerializer.query(q, txHandle));
}
});
} catch (Exception e) {
throw new JanusGraphException("Could not call index", e.getCause());
}
}
});
}


List<Object> resultSet = QueryUtil.processIntersectingRetrievals(retrievals, indexQuery.getLimit());
iter = com.google.common.collect.Iterators.transform(resultSet.iterator(), getConversionFunction(query.getResultType()));
} else {
if (config.hasForceIndexUsage()) throw new JanusGraphException("Could not find a suitable index to answer graph query and graph scans are disabled: " + query);
log.warn("Query requires iterating over all vertices [{}]. For better performance, use indexes", query.getCondition());

QueryProfiler sub = profiler.addNested("scan");
sub.setAnnotation(QueryProfiler.QUERY_ANNOTATION,indexQuery);
sub.setAnnotation(QueryProfiler.FULLSCAN_ANNOTATION,true);
sub.setAnnotation(QueryProfiler.CONDITION_ANNOTATION,query.getResultType());

switch (query.getResultType()) {
case VERTEX:
return (Iterator) getVertices().iterator();

case EDGE:
return (Iterator) getEdges().iterator();

case PROPERTY:
return new VertexCentricEdgeIterable(getInternalVertices(),RelationCategory.PROPERTY).iterator();

default:
throw new IllegalArgumentException("Unexpected type: " + query.getResultType());
}
}

return iter;
}

};

从方法中可以看出,当 JointIndexQuery 对象为空(arrayList 为空)且 force index 为 true 时会引发异常。
问题是为什么列表是空的?当我们针对 generate-modern.groovy 中的 name 属性指定索引查询时从 JUnit 测试中查询时。这意味着当相同的数据使用相同的文件预加载到 gremlin 服务器时,列表不为空。

最佳答案

personByName index definition使用标签约束。

def personByName = mgmt.buildIndex("personByName", Vertex.class).addKey(name).indexOnly(person).buildCompositeIndex()

为了利用该索引,您必须使用标签和属性。例如:
g.V().has('person', 'name', 'marko')

您可以在 JanusGraph 文档 http://docs.janusgraph.org/latest/indexes.html#_label_constraint 中阅读有关此内容的更多信息。

关于titan - 在 Titan/Janus 中启用力索引时索引失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45372399/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com