Titan 1.0 [Berkeley+ Remote Elastic Search] мы используем эту комбинацию Titan. Ниже приведен файл свойств -
storage.backend=berkeleyje
storage.directory=D:/other-projects/graph-db/titan/enron-tk3/db/berkeley
index.search.backend=elasticsearch
index.search.index-name=akshayatitan
index.search.hostname=localhost
index.search.elasticsearch.client-only=true
index.search.elasticsearch.local-mode=false
Мы используем только смешанный индекс.
Теперь мы добавляем узел с несколькими свойствами через код Java, а затем извлекаем его.
Мы запрашиваем свойство, для которого создается смешанный индекс.
Когда мы запрашиваем узел обратно по ключу (тот, для которого создается смешанный индекс), мы не получаем узел сразу. Однако он становится доступным с задержкой.
Что мы делаем не так? Или ожидается отложенное обновление экземпляра ES?
Вот код Java.
public static void main(String[] args) throws Exception {
GraphTest test = new GraphTest();
test.init();
Thread.sleep(10000);
String emailId = "emailId" + System.nanoTime();
test.createNode(emailId);
System.out.println("Create " + emailId);
System.out.println("First time " + test.getNode(emailId));
Thread.sleep(2000);
System.out.println("After a delay of 2 sec " + test.getNode(emailId));
}
public void createNode(String emailid) {
Vertex vertex = graph.addVertex("person");
vertex.property("emailId", emailid);
vertex.property("firstName", "First Name");
vertex.property("lastName", "Last Name");
vertex.property("address", "Address");
vertex.property("hometown", "Noida");
vertex.property("city", "Noida");
vertex.property("spousename", "Preeti");
graph.tx().commit();
}
public Object getNode(String emailId) {
Vertex vert = null;
String reString = null;
try {
vert = graph.traversal().V().has("emailId", emailId).next();
reString = vert.value("emailId");
} catch (NoSuchElementException e) {
e.printStackTrace();
} finally {
graph.tx().close();
}
return reString;
}
Код для создания индекса -
private void createMixedIndexForVertexProperty(String indexName, String propertyKeyName, Class<?> propertyType) {
TitanManagement mgmt = ((TitanGraph) graph).openManagement();
try {
PropertyKey propertyKey = makePropertyKey(propertyKeyName, propertyType, mgmt);
TitanGraphIndex graphIndex = mgmt.getGraphIndex(indexName);
if (graphIndex == null) {
graphIndex = mgmt.buildIndex(indexName, Vertex.class)
.addKey(propertyKey, Parameter.of("mapping", Mapping.STRING)).buildMixedIndex("search");
} else {
mgmt.addIndexKey(graphIndex, propertyKey);
}
mgmt.commit();
} catch (Exception e) {
mgmt.rollback();
} finally {
}
}
public PropertyKey makePropertyKey(String propertyKeyName, Class<?> propertyType, TitanManagement mgmt) {
PropertyKey propertyKey = mgmt.getPropertyKey(propertyKeyName);
if (propertyKey == null) {
propertyKey = mgmt.makePropertyKey(propertyKeyName).dataType(String.class).make();
}
return propertyKey;
}
public void init() throws Exception {
graph = TitanFactory
.open(new PropertiesConfiguration(new File("src/test/resources/titan-berkeleydb-es.properties")));
createMixedIndexForVertexProperty("personnode", "emailId", String.class);
createMixedIndexForVertexProperty("personnode", "firstName", String.class);
createMixedIndexForVertexProperty("personnode", "lastName", String.class);
createMixedIndexForVertexProperty("personnode", "address", String.class);
createMixedIndexForVertexProperty("personnode", "hometown", String.class);
createMixedIndexForVertexProperty("personnode", "city", String.class);
createMixedIndexForVertexProperty("personnode", "spousename", String.class);
}