Titan 1.0 [Berkeley + ES] - ES索引的延迟更新 [英] Titan 1.0[Berkeley+ES] - Delayed update of ES index

查看:295
本文介绍了Titan 1.0 [Berkeley + ES] - ES索引的延迟更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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(创建+ emailId);
System.out.println(First time+ test.getNode(emailId));
Thread.sleep(2000);
System.out.println(延迟2秒+ test.getNode(emailId));
}

public void createNode(String emailid){
顶点顶点= 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( 搜索);
} 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异常{
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);

}


解决方案

之前已经在 Titan邮件列表上讨论过。

$ b请注意,ES索引( index.refresh_interval )中有延迟。
您不能更新/插入一个值并立即查询。等待
至少1秒,然后再查询该值,否则结果可能是
为空。


你还应阅读Elasticsearch文档(修改您的数据近实时搜索 )索引行为:


弹性搜索在
附近实时提供数据操作和搜索功能。默认情况下,您可以从您索引/更新/删除数据的时间延迟一秒钟(刷新
间隔),直到出现在搜索结果中的
时间。这是一个重要的
与其他平台(如SQL)的区别,其中数据在事务完成后立即可用



注意 refresh_interval 期望一段时间,例如 1s (1秒)或 2m (2
分钟)。一个绝对的数字,如 1 意味着1毫秒 - 一个确定的方式,
使您的集群跪下。



Titan 1.0 [Berkeley+ Remote Elastic Search] we are using this combination of Titan. Following is the properties file -

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

We are only using Mixed Index.
Now we add a node with few properties through Java code and then fetch it.

We query by a property on which a mixed index is created.
When we query the node back by the key (one which mixed index is created) , we don't get the node immediately. However it get available after a delay.
What are we doing wrong ? Or is this delayed update of ES instance is expected?
Here is the Java code.

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

The code to create index is -

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

}

解决方案

This has been discussed before on the Titan mailing list.

note that there's a latency in ES indexing (index.refresh_interval). You can't update / insert a value and immediately query it. Wait at least 1 second before you query the value, otherwise the result may be empty.

You should also read up on the Elasticsearch documentation (modifying your data and near real-time search) on the indexing behavior:

Elasticsearch provides data manipulation and search capabilities in near real time. By default, you can expect a one second delay (refresh interval) from the time you index/update/delete your data until the time that it appears in your search results. This is an important distinction from other platforms like SQL wherein data is immediately available after a transaction is completed.

CAUTION The refresh_interval expects a duration such as 1s (1 second) or 2m (2 minutes). An absolute number like 1 means 1 millisecond--a sure way to bring your cluster to its knees.

这篇关于Titan 1.0 [Berkeley + ES] - ES索引的延迟更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆