我使用 Elastic Search 作为索引服务器。而且我有一个带有属性“poiId”的索引,但是当我使用该属性添加一个新顶点然后使用相同的远程遍历搜索它时,它什么也没找到。所以它继续添加新的顶点。代码有什么问题?
public class Loader {
public static void main(String[] args) throws Exception {
Graph graph = EmptyGraph.instance();
List<String> lines = IOUtils.readLines(FileUtils.openInputStream(new File(args[0])), "UTF-8");
for (String line : lines) {
GraphTraversalSource g = graph.traversal().withRemote("remote-graph.properties");
String[] cols = StringUtils.split(line, ",");
System.out.println(Arrays.asList(cols));
GraphTraversal<Vertex, Vertex> t1 = g.V().has("poiId", cols[0]);
GraphTraversal<Vertex, Vertex> t2 = g.V().has("poiId", cols[1]);
Object v1Id = null;
if (!t1.hasNext()) {
System.out.println(String.format("cols1 ADDED: %s", cols[0]));
v1Id = g.addV().property("poiId", cols[0]).next().id();
} else {
v1Id = t1.next().id();
}
Object v2Id = null;
if (!t2.hasNext()) {
System.out.println(String.format("cols2 ADDED: %s", cols[1]));
v2Id = g.addV().property("poiId", cols[1]).next().id();
} else {
v2Id = t2.next().id();
}
g.V(v1Id).as("a").V(v2Id).as("b").addE("relation").property("step", Integer.parseInt(cols[2])).from("a")
.to("b").next();
g.close();
}
}
}