How to use relationship index in Cypher

我只是一个虾纸丫 提交于 2019-12-22 06:57:07

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25871820/how-to-use-relationship-index-in-cypher

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!