如何在关系的属性上创建索引 [英] How to create an index on a property of a relation

查看:143
本文介绍了如何在关系的属性上创建索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个查询来获取关系的所有不为空的属性,例如

I need a query to fetch all properties of a relation that are not empty, e.g.

MATCH ()-[r:TYPE]-() WHERE r.attr <> "" RETURN r.attr

我猜想CREATE INDEX ON :TYPE(attr)在带有标签TYPE的节点上而不是在关系属性上创建索引吗?

I would guess that CREATE INDEX ON :TYPE(attr) creates an Index on a Node with the label TYPE and not on a relation property?

还是没有必要在关系属性上创建索引?

Or is it not necessary to create an index on a relation property?

我正在使用neo4j 2.2.3.

I am using neo4j 2.2.3.

推荐答案

只有使用最好创建这些图形,我强烈建议您重新考虑您的图形模型.凡是实体或复杂值类型的事物都应建模为节点.您世界中事物之间的交互被建模为关系. 通常,关系将权重参数或元数据用于其属性,但很少使用真实属性.

Bevor creating those I strongly recommend rethinking your graph model. Everything being an entity or a complex value type should be modeled as nodes. The interaction between the things in your world are modeled as relationships. Typically relationships use weight parameters or metadata for their properties but rarely real attributes.

由于查询通常从某物"(又称事物或节点)开始,因此您很可能不需要关系索引.索引仅应用于标识遍历的起点.

Since your queries typically start at "something" (aka a thing aka a node) you most likely don't need relationship indexes. Indexes should only be used for identifying the start points for your traversals.

这篇关于如何在关系的属性上创建索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆