【问题标题】:Neo4j - Cypher query returning wrong NodesNeo4j - Cypher 查询返回错误的节点
【发布时间】:2013-12-27 09:18:30
【问题描述】:

当尝试在密码中使用自动索引查询节点时,它会返回不相关的节点, 如下所示,我查询了具有 contno='GESU5697150' 的节点,但它也返回了其他一些节点。

neo4j-sh (0)$ start n=node:node_auto_index(contno='GESU5697150')  return n;
==> +----------------------------------------------------+
==> | n                                                  |
==> +----------------------------------------------------+
==> | Node[546290]{contno:"UACU5047693",sizetype:"40HC"} |
==> | Node[700914]{contno:"GESU5697150",sizetype:"40HC"} |
==> +----------------------------------------------------+
==> 2 rows 

这是 cypher / Neo4j 问题吗?!因此,我在获取 java 代码记录时遇到了问题

Ncontno = autoNodeIndex.get("contno", contno).getSingle();

它会抛出以下错误

Exception in thread "main" java.util.NoSuchElementException: More than one eleme
nt in org.neo4j.index.impl.lucene.LuceneIndex$1@211b3c6a. First element is 'Node
[546290]' and the second element is 'Node[700914]'

【问题讨论】:

  • 您能否分享一下您为导入数据所做的工作?
  • @Michael Hunger ,在代码下方使用 firstNode = null; firstNode = graphDb.createNode(); firstNode.setProperty("contno", contno); firstNode.setProperty("sizetype", sizetype); container.add(firstNode, "contno", contno); container.add(firstNode, "sizetype",sizetype);

标签: neo4j cypher


【解决方案1】:

Neo4j 中的自动索引不关心在自动索引配置更改时重新索引现有内容。如果在更改 contno 属性时关闭自动索引,您将看到所描述的行为。

要解决此问题,您可以使用其预先存在的值设置属性,从而触发自动索引的隐式更新:

start n=node:node_auto_index(contno='GESU5697150') set n.contno = n.contno

重新运行原始查询应该只返回一个元素。

Neo4j 2.0 中的架构索引解决了这种不便的行为,请参阅我在 Neo4j 中的blog post on various index types

【讨论】:

  • 1.If autoindexes were switched off while changing the contno property you'll see the described behaviour -- 自动索引在整个创建过程中开启。 2)我这样做了start n=node:node_auto_index(contno='GESU5697150') set n.contno = n.contno,但结果仍然相同。!!
  • 请参考以上评论!!
  • 您确定启用了自动索引吗?使用gist.github.com/sarmbruster/8001713 从你的messages.log 中获取最新的启动序列并将其上传到pastebin
  • 嗨,甚至在启用 auto_index 的情况下再次尝试了整个练习,但仍然出现相同的问题,然后尝试使用 IndexManager 进行相同的操作,但问题仍然存在..
  • 请参考以上评论并登录message.log
【解决方案2】:

通过验证结果集中的contno,我得到了上述问题的临时解决方案。

hits = container.get("contno", contno);
  for (Node n : hits) {
    if (n.getProperty("contno").toString().equalsIgnoreCase(contno)) {
           Ncontno = n;
    } 
  }

所以 Ncontno 将保持预期的 contno。但仍在寻找更好/永久的解决方案

【讨论】:

    猜你喜欢
    • 2020-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多