gpt4 book ai didi

elasticsearch - Titan存在索引时找不到合适的索引

转载 作者:行者123 更新时间:2023-12-03 02:04:44 26 4
gpt4 key购买 nike

我尝试在Berkeley上创建一个简单的Titan图系统,并且Titan不使用我为其查询创建的索引。

String INDEX_NAME = "search"
File dir=new File("C:/TEMP/titanTest1");
dir.mkdirs();
TitanFactory.Builder config = TitanFactory.build();
config.set("storage.backend", "berkeleyje");
config.set("storage.directory", dir.getAbsolutePath());
config.set("index."+INDEX_NAME+".backend","elasticsearch");
config.set("index." + INDEX_NAME + ".directory", new File(dir,"es").getAbsolutePath());
config.set("index."+INDEX_NAME+".elasticsearch.local-mode",true);
config.set("index."+INDEX_NAME+".elasticsearch.client-only",false);
config.set("query.force-index",true);
TitanGraph tg= config.open();
try {

if (tg.getPropertyKey("name")==null){
TitanManagement mgmt = tg.getManagementSystem();
VertexLabel metaclassLabel=mgmt.makeVertexLabel("metaclass").make();

final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
mgmt.buildIndex("metaClassesByName",Vertex.class).addKey(name).indexOnly(metaclassLabel).buildMixedIndex(INDEX_NAME);

mgmt.commit();
}

System.out.println("indexed:"+tg.getIndexedKeys(Vertex.class));

Vertex v=tg.addVertexWithLabel("metaclass");
v.setProperty("name", "test");

for (Object o:tg.query().has("name").has(ImplicitKey.LABEL.getName(), "metaclass").vertices()){
Vertex v2=(Vertex)o;
System.out.println(v2);
}
tg.commit()
} finally {
tg.shutdown();
}

此代码打印:
 indexed:[name]
Exception in thread "main" com.thinkaurelius.titan.core.TitanException: Could not find a suitable index to answer graph query and graph scans are disabled: [(name <> null AND label = metaclass)]:VERTEX
at com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx$8.execute(StandardTitanTx.java:1198)

我不明白为什么Titan不能使用我定义的索引。我想列出所有具有元类标签的对象。唯一有效的方法是定义一个复合索引,并使用确切的名称值搜索一个顶点。反正有可能吗?

谢谢!

最佳答案

您可以使用直接索引查询:

for (Result<TitanVertex> res : g.indexQuery("metaClassesByName","v.name:*").vertices()) {
Vertex v2 = res.getElement();
System.out.println(v2);
}

关于elasticsearch - Titan存在索引时找不到合适的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27984147/

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