elasticsearch Titan 1.0[Berkeley+;ES]-ES索引的延迟更新
Titan 1.0[伯克利+远程弹性搜索] 我们正在使用泰坦的这种组合。以下是属性文件-elasticsearch Titan 1.0[Berkeley+;ES]-ES索引的延迟更新,elasticsearch,transactions,titan,tinkerpop3,elasticsearch,Transactions,Titan,Tinkerpop3,Titan 1.0[伯克利+远程弹性搜索] 我们正在使用泰坦的这种组合。以下是属性文件- 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 i
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);
}
private void createMixedIndexForVertexProperty(String indexName、String propertyKeyName、Class propertyType){
TitanManagement管理=((TitanGraph)图形)。OpenManage();
试一试{
PropertyKey PropertyKey=makePropertyKey(PropertyKey名称、propertyType、管理);
TitanGraphIndex graphIndex=mgmt.getGraphIndex(indexName);
if(graphIndex==null){
graphIndex=mgmt.buildIndex(indexName,Vertex.class)
.addKey(propertyKey,Parameter.of(“mapping”,mapping.STRING)).buildMixedIndex(“search”);
}否则{
管理addIndexKey(graphIndex、propertyKey);
}
mgmt.commit();
}捕获(例外e){
管理回滚();
}最后{
}
}
公共属性key makePropertyKey(字符串propertyKeyName、类propertyType、管理管理){
PropertyKey PropertyKey=mgmt.getPropertyKey(propertyKeyName);
如果(propertyKey==null){
propertyKey=mgmt.makePropertyKey(propertyKeyName).dataType(String.class.make();
}
归还财产;
}
public void init()引发异常{
图=泰坦工厂
.open(新属性配置(新文件(“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”、“家乡”、String.class);
createMixedIndexForVertexProperty(“personnode”,“city”,String.class);
createMixedIndexForVertexProperty(“personnode”、“SpooseName”、String.class”);
}
这一点之前已在上讨论过
请注意,ES索引中存在延迟(index.refresh\u interval
)。
无法更新/插入值并立即查询它。等候
在查询值前至少1秒,否则结果可能是错误的
空的
您还应该阅读Elasticsearch文档(和),了解索引行为:
Elasticsearch在中提供数据操作和搜索功能
接近实时。默认情况下,您可以预期一秒钟的延迟(刷新)
从索引/更新/删除数据到
它出现在搜索结果中的时间。这是一个重要的问题
与其他平台(如SQL)的区别在于,在SQL平台中,数据可以立即存储
交易完成后可用
注意刷新间隔预计持续时间为1s
(1秒)或2m
(2
分钟)。像1
这样的绝对数意味着1毫秒——这是一个确定的方法
把你的簇放在膝盖上
谢谢你,杰森。我试图搜索,但没有得到相关信息。您的回答很准确。这是我们想要实现的用途,因为我们必须实时查询记录。我们想要搜索图形数据,因此需要NGRAM支持部分搜索。不幸的是,我们无法用默认的ES索引(Titan)实现这一点。对自定义索引创建的支持不够。因此,我们最终创建了另一个具有所需配置的索引(ngram)。现在我们有一项工作来保持它们的同步,所以需要不断地将数据从titan索引更新到ngram索引。我们还希望保持这些记录的ID不变。因此,当记录被更新时,我们查询titan索引,获取数据并使用相同的索引id将其复制到ngram。正是为了保持id同步,我们必须实时从titan查询,导致了这个问题。然而,我们发现ES id=LongEncoding.encode(顶点id)这种两个数据源的方法是一个问题,但是由于对索引定制的支持有限(从我们目前收集的数据来看),这是很困难的。我认为这应该是一个很好的用例,可以提供一个增强。