如何在Cypher中使用关系索引 [英] How to use relationship index in Cypher
问题描述
我正在使用neo4j 2.1.4。
我有节点 - POINT和关系 - ROAD
我有ROAD属性的索引 - OBJ_COD
: schema ls -l:ROAD
索引
ON:ROAD(OBJ_COD)ONLINE
ON:ROAD(ID)ONLINE
无约束
我想通过OBJ_COD值搜索ROAD,但是cypher不用索引来查找关系。
pre $
neo4j-sh(?)$ profile MATCH(a) - [r:`ROAD` {ID:333275}] - (b:`POINT `)RETURN r极限1;
ColumnFilter
|
+ TraversalMatcher
+ ------------------ + ------ + --------- + ------------- + ---------------- +
|运算符|行| DbHits |标识符|其他|
+ ------------------ + ------ + --------- + --------- ---- + ---------------- +
| ColumnFilter | 2 | 0 | |保留列r |
| TraversalMatcher | 2 | 2265843 | | a,r,a |
+ ------------------ + ------ + --------- + --------- ---- + ---------------- +
如何强制cypher使用现有的索引来搜索单个关系?
架构索引仅在节点上可用。对关系进行索引的需求几乎总是会在图形数据建模中出现问题。通常,您可以使用索引查找图遍历的起点。良好的建模实践是,你的域中的任何东西都应该是一个节点,并且这个关系把你的事物
或实体
code> things 转换成语义上下文。如果你关注这个,你的查询开始于某些东西
,那么就不需要索引关系。
然而,关系索引可能是一个有效的选择的一些罕见情况。在这种情况下,您需要回退以使用传统索引进行关系。阅读精美的文档,了解它们的工作原理。
I'm using neo4j 2.1.4. I have nodes - POINT and relationships - ROAD I have index on ROAD property - OBJ_COD
:schema ls -l :ROAD
Indexes
ON :ROAD(OBJ_COD) ONLINE
ON :ROAD(ID) ONLINE
No constraints
I want to search ROAD by OBJ_COD value, but cypher don'use index to lookup relationship.
neo4j-sh (?)$ profile MATCH (a)-[r:`ROAD` {ID:333275}]-(b:`POINT`) RETURN r LIMIT 1;
ColumnFilter
|
+TraversalMatcher
+------------------+------+---------+-------------+----------------+
| Operator | Rows | DbHits | Identifiers | Other |
+------------------+------+---------+-------------+----------------+
| ColumnFilter | 2 | 0 | | keep columns r |
| TraversalMatcher | 2 | 2265843 | | a, r, a |
+------------------+------+---------+-------------+----------------+
How can I force cypher to use existing index to search single relationship?
Schema index are only available on nodes. The need for having indexes on relationships almost always unveils an issue in your graph data modelling. Typically you use indexes to look up start points for graph traversals. Good modelling practice is that anything in your domain being a thing
or entity
should be a node and the relationship put your things
into a semantic context. If you follow this and your queries start at something
there will be no need for indexing relationships.
However there are some rare case where relationship indexing might be a valid choice. In this case you need to fall back to use legacy indexes for relationships. Review the fine documentation for this to understand how they work.
这篇关于如何在Cypher中使用关系索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!