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