Indexing in Neo4j: An Overview

by Stefan Armbruster · Jan. 06, 14 · Java Zone

Neo4j是一个图数据库,在做图的检索时,用index确定图检索graph travesal的起始节点start point。过去的数次版本更迭,index索引的实现方式发生了多次变化。这个Overview的主要目的是解释一下各种index方式的由来和概念,以使neo4j的新用户不产生概念上的混淆。

No Indexes in the Beginning

一开始,neo4j是没有Index索引的。在做graph的遍历的时候,需要从Reference Node开始。只有通过给Node绑定一些标志来获得Reference Node。Reference Node或者”Node 0”被当作一个全局的变量使用。直到neo4j 1.9.x 版本,GraphDatabaseService类有了getReferenceNode()方法,来获取Reference Node。当然,getReferenceNode()方法在neo4j 2.0版本以后已经被废弃了。

Manual Indexes

Manual Index(手动索引,先这么翻译吧~)在neo4j 1.0版本之前已经开始筹备了,那时候neo4j还没有Cypher和server模式,只能使用java API操作Graph。Manual Index是通过java API添加的。

建manual Index的方法

IndexManager index = graphDb.index();
Index<Node> nodeIndex = index.forNodes( "nodes" );
Node node = graphDb.createNode();
nodeIndex.add( node, "name", "Thomas Anderson" );

如果有manual index,可以用cypher查询:

START n=node:Person(name='abc') RETURN n

manual index的缺点

1、建manual索引比较麻烦。

2、程序员会滥用index,index应该只用于检索,而不应该存储多余的信息。

manual index的优点

可以自己控制建索引是使用什么分词器(Analyzer)

参考: http://docs.neo4j.org/chunked/stable/indexing-create-advanced.html.

35.10. Configuration and fulltext indexes

At the time of creation extra configuration can be specified to control the behavior of the index and which backend to use. For example to create a Lucene fulltext index:

IndexManager index = graphDb.index();
Index<Node> fulltextMovies = index.forNodes( "movies-fulltext", MapUtil.stringMap( IndexManager.PROVIDER, "lucene", "type", "fulltext"));
fulltextMovies.add( theMatrix, "title", "The Matrix" );
fulltextMovies.add( theMatrixReloaded, "title", "The Matrix Reloaded" );
// search in the fulltext index
Node found = fulltextMovies.query( "title", "reloAdEd" ).getSingle();

Here’s an example of how to create an exact index which is case-insensitive:

Index<Node> index = graphDb.index().forNodes( "exact-case-insensitive", stringMap( "type", "exact", "to_lower_case", "true" ) );
Node node = graphDb.createNode();
index.add( node, "name", "Thomas Anderson" );
assertContains( index.query( "name", "\"Thomas Anderson\"" ), node );
assertContains( index.query( "name", "\"thoMas ANDerson\"" ), node );

Automatic Indexes

Neo4j 1.4引入了自动索引(automatic index),使用自动建索引,在config/neo4j.properties中配置。

参考:http://www.cnblogs.com/nyzhai/p/4515102.html

# Enable auto-indexing for nodes, default is false.
node_auto_indexing=true
# The node property keys to be auto-indexed, if enabled.
node_keys_indexable=name,ki
# Enable auto-indexing for relationships, default is false.
relationship_auto_indexing=true
# The relationship property keys to be auto-indexed, if enabled.
relationship_keys_indexable=name,ki

cypher使用自动索引

START n=node:node_auto_index(name='abc') RETURN n

Schema Indexes

cypher建schema Index:

CREATE INDEX ON :Person(name);

使用schema Index:

MATCH (p:Person {name: 'Stefan'}) RETURN p

cypher查询时,如果有schema Index会使用索引;如果没有,会逐条扫描。schema Index索引是透明的。

Reference:

https://dzone.com/articles/indexing-neo4j-overview

原文地址:https://blog.csdn.net/u011697278/article/details/52462420

Neo4j:Index索引的更多相关文章

  1. neo4j中索引的使用

    neo4j可以对node和relationship中的属性建立索引,索引中的node(relationship)和属性对key-value为多对多的关系.一个node(relationship)可以在 ...

  2. nexus私服update repair index索引失败解决方案(转)

    转载地址:http://blog.csdn.net/first_sight/article/details/51559086 问题描述: 搭建Maven的Nexus私服仓库,一般安装完Nexus后,默 ...

  3. 加NONCLUSTERED INDEX索引,在ON了之后还要INCLUDE

    之前加了索引,但效果不大 SET STATISTICS TIME ON --执行时间 SET STATISTICS IO ON --IO读取 DBCC DROPCLEANBUFFERS --清除缓冲区 ...

  4. py-day1-6 python 5个灰魔法 【len,index索引,for循环,切片】

    # 索引,下标,获取字符串中的某一个字符. test = 'MuMingJun' v = test[3] print(v) i # 切片 test = 'MuMingJun' v = test[0:- ...

  5. index索引的一些简单理解

    index索引(普通索引,允许出现相同的索引内容) 1.索引 索引是在数据量和访问量较大的时候,而出现的一种优化数据库的手段 索引可以提高查询(select)的效率,但相应的,它的 INSERT 与 ...

  6. 根据日志来源的不同生成不同的index索引

    使用filebeat收集系统日志,不同应用的日志,然后把这些日志传输给Logstash,再然后交由elasticsearch处理,那么如何区分不同的日志来源呢? filebeat.yml配置文件中不启 ...

  7. 微信小程序获取index索引值的方法

    功能:点击某一项,底部出现粉色边框 首先需要通过 bindtap 为每一个item项绑定一个点击事件,其次需要添加自定义属性 data-* = {{index}} ,以便在函数中获取到被点击item项 ...

  8. 【mq读书笔记】Index索引文件

    1.IndexHeader头部,40字节,记录IndexFile的统计信息: begainTimestamp:该索引文件中包含消息的最小存储时间 endTimestamp:该索引文件中包含消息的最大存 ...

  9. MySQL查询优化之 index 索引的分类和使用

    索引的分类 主键索引 (PRIMARY KEY) 唯一的标识符, 主键不可重复, 只能有一列作为主键 唯一索引 (Unique KEY) 避免重复的列出现, 唯一索引可以重复, 多个列都可以标识为唯一 ...

随机推荐

  1. winserver 2008 找不到回收站的解决办法

    桌面新建文件夹,命名为 “回收站.{645ff040-5081-101b-9f08-00aa002f954e}”,就可以了.

  2. python中datetime模块中strftime/strptime函数

    f==format p==parse 1.获取当前时间(日期格式) from datetime import datetime datetime.now()#输出 datetime.datetime( ...

  3. Spring学习笔记(5)——IoC再度学习

    学习过Spring框架的人一定都会听过Spring的IoC(控制反转) .DI(依赖注入)这两个概念,对于初学Spring的人来说,总觉得IoC .DI这两个概念是模糊不清的,是很难理解的,今天和大家 ...

  4. Oracle使用存储过程返回查询游标

    如果报表逻辑非常复杂的话, 可以把报表逻辑放到存储过程里,加工一个全局临时表.前端查询的时候只查询临时表即可.只是第一次查询需要忍受加工的时间. --创建存储过程,返回SYS_REFCURSOR CR ...

  5. shell只读变量

  6. linux sed删除^M换行符以及^[[转义字符

    1. 删除文档中的蓝色转义字符^M 注意:^M 不能从键盘输入^和M,也不能复制.而是需要按Ctrl+v 然后再按Ctrl+M 按Ctrl+v的时候屏幕不会输出,再按下Ctrl+M的时候即会出现^M  ...

  7. 论文学习——《Learning to Compose with Professional Photographs on the Web》 (ACM MM 2017)

    总结 1.这篇论文的思路基于一个简单的假设:专业摄影师拍出来的图片一般具备比较好的构图,而如果从他们的图片中随机抠出一块,那抠出的图片大概率就毁了.也就是说,原图在构图方面的分数应该高于抠出来的图片. ...

  8. C# 进制转换(二进制、十六进制、十进制互转) 转载 https://www.cnblogs.com/icebutterfly/p/8884023.html

    C# 进制转换(二进制.十六进制.十进制互转)由于二进制数在C#中无法直接表示,所以所有二进制数都用一个字符串来表示例如: 二进制: 1010 表示为 字符串:"1010" int ...

  9. spark算子之Aggregate

    Aggregate函数 一.源码定义 /** * Aggregate the elements of each partition, and then the results for all the ...

  10. 设计不严谨 - Get参数传日期空格未转义字符出现截断请求,后端无法处理

    设计不严谨 Get参数传递日期的时候有空格,如果未转义的话,会截断请求,然后后端无法处理. 从业务场景看 从产品的角度看,产品想要看每个活动的效果,而不是想知道技术. 角度不同,视觉不同 mark