Neo4j问题与加强索引 [英] Neo4j issue with enforcing indexes
问题描述
我遇到了在Cypher批查询中强制使用索引的问题,
I'm running into an issue where I'm enforcing the use of an index in a Cypher batch query,
UNWIND {rows} AS row
MATCH (s:Entity)
USING INDEX s:Entity(uuid)
WHERE s.uuid = row.source
MATCH (t:Entity)
USING INDEX t:Entity(uuid)
WHERE t.uuid = row.target
MATCH (s)-[r:CONSUMED]->(t)
DELETE r
其中row.source
和row.target
以及两个UUID字符串.问题是我收到错误ERROR - Cannot use index hint in this context
.
where row.source
and row.target
and both UUID strings. The issue is I get the error, ERROR - Cannot use index hint in this context
.
如果我扩展查询以仅返回Neo4j UI中特定源节点和目标节点的关系,即
If I augment the query to merely return the relationship for a specific source and target node in the Neo4j UI, i.e.
MATCH (s:Entity)
USING INDEX s:Entity(uuid)
WHERE s.uuid = '04bc79e1-a836-11e6-b841-22000bcec6a9'
MATCH (t:Entity)
USING INDEX t:Entity(uuid)
WHERE t.uuid = 'a245f46a-a837-11e6-b841-22000bcec6a9'
MATCH (s)-[r:CONSUMED]->(t)
RETURN r
没有引发错误并返回了关系,因此我有点困惑可能是什么问题?
no error is thrown and the relationship is returned, and thus I'm somewhat perplexed what the issue could be?
推荐答案
[更新]
您的第二个查询也更改了WHERE
子句,这就是它起作用的原因.
Your second query also changed the WHERE
clauses, which is why it worked.
neo4j当前不支持将
neo4j does not currently support using the USING INDEX
clause for an index that will be used to compare property values to each other (as you do in your first query).
注意:在这种情况下,neo4j的最新版本实际上可以使用索引,但是如果尝试指定USING INDEX
子句作为提示,则neo4j会抱怨.这可能是一个错误.我为此提交了问题8463 .
Note: the latest versions of neo4j are actually able to use the index in that scenario, but if you try to specify the USING INDEX
clause as a hint, neo4j will complain. This is probably a bug. I have submitted Issue 8463 for this.
但是,当使用索引将属性值与标识符或文字进行比较时,neo4j的USING INDEX
子句没有问题(就像您在第二个查询中所做的那样).
However, neo4j has no problems with the USING INDEX
clause when the index is used to compare a property value to an identifier or a literal (as you do in your second query).
幸运的是,有一个简单的解决方法.您可以只为属性值创建标识符,而改用这些标识符.例如,在这里查看WITH
子句的用法:
Luckily, there is a simple workaround. You can just create identifiers for the property values and use those identifiers instead. For example, see how the WITH
clause is used here:
UNWIND {rows} AS row
WITH row.source AS source, row.target AS target
MATCH (s:Entity)
USING INDEX s:Entity(uuid)
WHERE s.uuid = source
MATCH (t:Entity)
USING INDEX t:Entity(uuid)
WHERE t.uuid = target
MATCH (s)-[r:CONSUMED]->(t)
DELETE r
这篇关于Neo4j问题与加强索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!