cypher 2.0:使用基于标签的索引来搜索一组节点 [英] cypher 2.0 : using label based index to search a set of nodes
问题描述
我有它们属于的users
和groups
.
我有一个索引n:Group(name)
I have users
and groups
they belong to.
I have an index n:Group(name)
我要搜索属于一组组的所有用户:["gr1","gr2","gr3"]
I want to search for all users belong to a set of groups : ["gr1","gr2","gr3"]
它们属于哪个其他组.
所以我有以下查询: 查询:
so I have the following query: Query :
MATCH (gr:Group) <--(us:User)--(gr2:Group)
WHERE gr.name in ["gr1","gr2"]
return distinct gr2
这里的事情是,我认为cypher不使用索引,因为查询速度很慢.
The thing here, is that I think that cypher don't use the index because the query is to slow.
我有2k个节点,有50k个关系. 以下查询需要200到700毫秒(取决于缓存):
I have 2k nodes, 50k relationships. The following query takes between 200 to 700 ms (depending on cache):
MATCH (gr:Group) <--(us:User)--(gr2:Group)
WHERE gr.name = "gr1"
return distinct gr2
但是,以下查询需要2到6秒钟!
However, the following query, takes between 2 to 6 seconds!
MATCH (gr:Group) <--(us:User)--(gr2:Group)
WHERE gr.name in ["gr1"]
return distinct gr2
当我尝试做时:
MATCH (gr:Group) <--(us:User)--(gr2:Group)
using index gr:Group(name)
WHERE gr.name in ["gr1"]
return distinct gr2
我收到以下错误:
Cannot use index hint in this context. The label and property comparison must be specified on a non-optional node
Label: `Group`
Property name: `name`
(用"="代替"in",我没有收到错误)
(with "=" instead of "in" I get no error)
我正在使用neo4j enterprise 2.0.1.测试结果来自在neo4j浏览器上运行.
I'm using neo4j enterprise 2.0.1 . The test results are from running on the neo4j browser .
推荐答案
当您在(gr:Group {name: "gr1"})
中指定模式中的属性或调用WHERE gr.name = "gr1"
时,将引用索引.如果可能有多个attrib值,则可以使用OR
子句.
The index is referred either when you specify the attribs in the pattern as in (gr:Group {name: "gr1"})
or you call WHERE gr.name = "gr1"
. In your case where multiple attrib values are possible you can use OR
clause.
MATCH (gr:Group) <--(us:User)--(gr2:Group)
WHERE gr.name="gr1" OR gr.name="gr2"
return distinct gr2
这篇关于cypher 2.0:使用基于标签的索引来搜索一组节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!