使用janusgraph的withRemote遍历(gremlin语言)似乎与Index有问题

时间:2017-08-24 11:59:30

标签: gremlin tinkerpop janusgraph

我使用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();
    }

}

}

0 个答案:

没有答案