【问题标题】:Neo4J: Automatic Indexing on Batch ExecutionNeo4J:批量执行的自动索引
【发布时间】:2014-01-26 19:40:08
【问题描述】:

是否可以使用自动索引功能在 Neo4J 上导入数据?我正在尝试使用 BatchInserter 和 BatchInserterIndex 导入数据,如下例所示:

BatchInserter inserter = BatchInserters.inserter("/home/fmagalhaes/Neo4JDatabase");
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(inserter);
BatchInserterIndex nodeIndex = indexProvider.nodeIndex("node_auto_index", MapUtil.stringMap("type","exact"));
BatchInserterIndex relIndex = indexProvider.relationshipIndex("relationship_auto_index", MapUtil.stringMap("type","exact"));
...
inserter.createNode(vertexId, properties);
nodeIndex.add(vertexId, properties);
...

问题是,当批处理完成后,我正在尝试通过执行以下操作使用 Blueprints 通用 API 打开此数据库:

Graph g = new Neo4jGraph("/home/fmagalhaes/Neo4JDatabase");
Set<String> nodeIndices = ((KeyIndexableGraph)g).getIndexedKeys(Vertex.class);
Set<String> relIndices = ((KeyIndexableGraph)g).getIndexedKeys(Edge.class);

并且 nodeIndices 和 relIndices 都是空的。当我在 Blueprints API 上打开图形数据库时,自动索引功能被禁用。是否可以在批处理期间创建一个自动索引,以便在我使用 Blueprints API 打开数据库时,该索引将可见(并且将继续自动索引数据,因为属性被添加到顶点和边)?

【问题讨论】:

    标签: neo4j tinkerpop


    【解决方案1】:
    1. 您必须彻底关闭批处理索引和批处理插入器
    2. 您可能不想索引所有属性,而只想索引用于查找节点的关键属性
    3. 您必须在 neo4j 配置中为之后启动的数据库以及在批量插入期间索引的相同属性启用自动索引

    【讨论】:

    • 1.我已经在上面的示例中省略了,但我正在关闭 IndexProvider 和 BatchInserter。 2. 正确。事实上,我正在测试蓝图和 Neo4J,我使用的唯一属性是:“__id”。我想索引这个属性,因为我想使用 Blueprints API 中的 IdGraph 包装器。 3. 如何在嵌入式 Neo4j 数据库上启用自动索引?打开数据库时是否应该使用node_auto_indexing=true和relationship_auto_indexing=true配置?
    • 另外,当我只使用 Blueprints API(和 Neo4jGraph 类实现)而不是使用 BatchInserts 导入数据时,当我使用 createKeyIndex() 方法时,我可以稍后打开数据库直接指向而不需要设置 node_auto_indexing=true 和 relationship_auto_indexing=true。不知何故,此配置嵌入在数据库本身中。是否可以在使用 BathInserts 时将这种 auto_index 行为嵌入到数据库中,而不必在打开数据库时在配置中手动设置它们?
    猜你喜欢
    • 1970-01-01
    • 2017-06-05
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    • 1970-01-01
    • 2011-10-22
    • 1970-01-01
    • 2018-07-10
    相关资源
    最近更新 更多