【问题标题】:Adding index on neo4j node property value在 neo4j 节点属性值上添加索引
【发布时间】:2014-09-11 02:40:26
【问题描述】:

我已将 freebase 转储导入 neo4j。但是由于数据库的大小,目前我面临获取查询的问题。导入时,我刚刚创建了节点索引并索引了 URI 属性以索引每个节点。对于每个节点,我添加了多个属性,例如 label_en、type_content_type_en。

props.put(URI_PROPERTY, subject.stringValue());

Long subjectNode = db.createNode(props);

tmpIndex.put(subject.stringValue(), subjectNode);

nodeIndex.add(subjectNode, props);

现在我的密码查询是这样的。哪些正在超时。我无法在 label_en 属性上添加索引。有人可以帮忙吗?

match (n)-[r*0..1]->(a) where n.label_en=~'Hibernate.*' return n, a

更新

BatchInserter db = BatchInserters.inserter("ttl.db", config);
BatchInserterIndexProvider indexProvider = new LuceneBatchInserterIndexProvider(db);
BatchInserterIndex index = indexProvider.nodeIndex("ttlIndex", MapUtil.stringMap("type", "exact"));

问题:当我在 nodeindex 中添加节点时,我添加了属性 URI

props.put(URI_PROPERTY, subject.stringValue());
Long subjectNode = db.createNode(props);
nodeIndex.add(subjectNode, props);

稍后在代码中,我向节点添加了另一个属性(命名为 label_en)。但我没有添加或更新 nodeindex。因此,据我了解,lucene 没有索引 label_en 属性。我的图表已经构建好了,所以我正在尝试在我的节点的 label_en 属性上添加索引,因为我的查询位于 label_en 上。

【问题讨论】:

    标签: neo4j


    【解决方案1】:

    您的代码示例缺少您创建索引的方式。但我很确定您正在使用的是基于 Apache Lucene 的遗留索引。

    您的 Cypher 查询正在使用正则表达式运算符 =~。这不是您使用旧索引的方式。这似乎迫使 cypher 忽略遗留索引,并让 java 层在 label_en 属性的每个可能值上运行该正则表达式。

    相反,您应该使用 Cypher use a START clause and use the legacy indexing query language

    对你来说,这看起来像这样:

    START n=node:my_index_name("label_en:Hibernate.*")
    MATCH (n)-[r*0..1]->(a)
    RETURN n, a;
    

    注意字符串label_en:Hibernate.* - 这是一个Lucene 查询字符串,表示要检查该特定字符串的属性名称。 Cypher/neo4j 没有解释这一点;它正在将其传递给 Lucene。

    您的代码未提供索引的名称。您必须将上面的 my_index_name 更改为您在创建旧索引时命名的任何名称。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-10-03
      • 1970-01-01
      • 1970-01-01
      • 2016-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多