JanusGraph Cassandra 索引需要重新索引吗?

问题描述 投票:0回答:1

JanusGraph 索引是否需要在加载更多数据后重新索引?

我知道这是一个新手问题,但我是这个问题的新手。
根据我现在的理解,OrientDB 和 Neo4j 没有;而且我认为大多数 SQL 数据库服务器默认会自动自我管理自己的维护。但是,我只是想确保在检查 JanusGraph 的性能时正确测试它。

我没有找到 JanusGraph Docs 告诉我它明确地维护或不维护它的索引; 我也没有看到 JanusGraph 向我展示示例索引输出和日志。 而且我特别不知道使用

"inmemory"
与使用 backend-server Cassandra 相比行为是否会改变。 另外,一些示例使用了Oracle Berkeley DB,这让我对后端服务器的特定问题更加不确定。

import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.janusgraph.core.JanusGraph;
import org.janusgraph.core.JanusGraphFactory;
import org.janusgraph.core.JanusGraphVertex;
import org.janusgraph.core.PropertyKey;
import org.janusgraph.core.schema.JanusGraphManagement;

public class Main {
    public static void main(String[] args) {
        JanusGraph janusGraph = JanusGraphFactory.build().set("storage.backend", "cql").set("storage.hostname", "localhost:9042").open();
        JanusGraphManagement janusGraphManagement = janusGraph.openManagement();
        PropertyKey propertyKey = janusGraphManagement.getOrCreatePropertyKey("_id");
        if (!janusGraphManagement.containsGraphIndex("_id"))
            janusGraphManagement.buildIndex("_id", Vertex.class).addKey(propertyKey).buildCompositeIndex();
        janusGraphManagement.commit();
        JanusGraphVertex janusGraphVertex = janusGraph.addVertex();
        janusGraphVertex.property("test","test");
        janusGraph.tx().commit();
        janusGraphVertex = janusGraph.addVertex();
        janusGraphVertex.property("test","test2");
        janusGraph.tx().commit();
        janusGraph.close();
    }
}
    <dependencies>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
            <version>2.20.0</version>
        </dependency>
        <dependency>
            <groupId>org.janusgraph</groupId>
            <artifactId>janusgraph-cql</artifactId>
            <version>1.0.0-20230504-014643.988c094</version>
        </dependency>
    </dependencies>
gremlin cassandra-3.0 janusgraph tinkerpop3 java-17
1个回答
1
投票

如果在创建索引的同一事务中创建要索引的键和标签,则无需重新索引。

如果您需要提取在创建索引之前创建的任何内容,则需要执行重新索引步骤。

完成并提交事务后,您应该能够开始添加数据并编写利用您创建的索引的查询。

使用

.profile()
结束 Gremlin 查询将向您显示查询运行时用于帮助执行查询的索引(如果有的话)。

最简单的实验方法是使用

inmemory
图表并使用以下命令从 Gremlin 控制台启动它:

gremlin> g=JanusGraphFactory.open('inmemory').traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
© www.soinside.com 2019 - 2024. All rights reserved.