【问题标题】:Titan 1.0[Berkeley+ES] - Delayed update of ES indexTitan 1.0[Berkeley+ES] - ES索引延迟更新
【发布时间】:2016-08-09 18:09:30
【问题描述】:

Titan 1.0 [Berkeley+ 远程弹性搜索] 我们正在使用 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);

}

【问题讨论】:

    标签: elasticsearch transactions titan tinkerpop3


    【解决方案1】:

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

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

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

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

    注意 refresh_interval 需要一个持续时间,例如 1s(1 秒)或 2m(2 分钟)。像1 这样的绝对数字意味着 1 毫秒——这是一种肯定的方法 让您的集群屈服。

    【讨论】:

    • 谢谢杰森。我试图搜索但没有得到相关信息。您的回答很到位。
    • 这是我们想要实现的用途,因此我们必须实时查询记录。
    • 我们要搜索图形数据,因此需要 NGRAM 支持部分搜索。不幸的是,我们无法使用默认的 ES 索引(Titan)来实现这一点。对自定义索引创建的支持是不够的。所以我们最终创建了另一个具有所需配置的索引(ngram)。现在我们的工作是让它们保持同步,因此需要不断将数据从 Titan 索引更新到 ngram 索引。我们还希望保持这些记录的 ID 相同。因此,当记录更新时,我们会查询 Titan 索引,获取数据并将其复制到具有相同索引 ID 的 ngram。
    • 为了保持id同步,我们不得不从titan实时查询,导致了这个问题。但是我们发现 ES id =LongEncoding.encode(vertex id) 这种两个数据源的方法是有问题的,但是由于对索引自定义的支持有限(从我们目前收集的信息来看),这很困难。我认为这应该是一个很好的用例,并且可以提供增强功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 2014-09-10
    • 2013-09-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多