0

I'm using Elastic Search as index server. And I have an index with property "poiId", but when I added a new vertex with that property and then search for it using the same remote traversal, it found nothing. So it continues adding new vertexes. What's wrong with code?

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

}

}

Gao
  • 912
  • 6
  • 16
  • How did you define the index? What does the `remote-graph.properties` look like? – Jason Plurad Aug 24 '17 at 23:46
  • @JasonPlurad I think the index is not working, the janus graph 's ES client is outdated... – Gao Aug 25 '17 at 03:02
  • Are you using an ES version that is compatible with the JanusGraph [supported version](http://docs.janusgraph.org/latest/version-compat.html)? For exact match lookups, you don't need ES anyway. [Composite index](http://docs.janusgraph.org/latest/indexes.html#graph-indexes) would be fine. My questions from before still stand. – Jason Plurad Aug 25 '17 at 07:16

0 Answers0