首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Titan 1.0[Berkeley+ES] - ES索引更新延迟

Titan 1.0[Berkeley+ES] - ES索引更新延迟
EN

Stack Overflow用户
提问于 2016-04-18 14:12:19
回答 1查看 185关注 0票数 1

Titan 1.0 Berkeley+远程弹性搜索我们使用的是Titan的这种组合。以下是属性文件-

代码语言:javascript
复制
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代码。

代码语言:javascript
复制
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;
}

创建索引的代码是-

代码语言:javascript
复制
    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);

}
EN

回答 1

Stack Overflow用户

发布于 2016-04-18 21:52:42

这之前已经在Titan mailing list上讨论过了。

注意到ES索引(index.refresh_interval)中存在延迟。您不能更新/插入一个值并立即查询它。查询前至少等待1秒,否则查询结果可能为空。

您还应该阅读有关索引行为的Elasticsearch文档(modifying your datanear real-time search):

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

CAUTION refresh_interval期望的持续时间为1s (1秒)或2m (2分钟)。像1这样的绝对数字意味着1毫秒--这肯定会让集群崩溃。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36686620

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档