Neo4j节点属性包含原始json作为元数据

时间:2021-12-20 18:00:17

Is this possible to have a node property as json raw string and to filter on it with cypher ? I have a node with some defined properties and metadata (json raw string). I would like to select or filter on those metadata property. This is something like this :

是否可以将节点属性作为json原始字符串并使用cypher对其进行过滤?我有一个节点,其中包含一些已定义的属性和元数据(json原始字符串)。我想选择或过滤那些元数据属性。这是这样的:

START movie=node:TYPE_INDEX(Type = 'MOVIE') // Start with the reference
MATCH movie-[t:TAG]->tag 
WHERE collect(movie.Metadata).RatingPress > 3
RETURN distinct movie.Label

And metadata are something like this :

元数据是这样的:

{"RatingPress" : "0","RatingSpectator" : 3"}

I have expected to use collect function in order to call the property like this :

我希望使用collect函数来调用属性,如下所示:

collect(movie.Metadata).RatingPress

But, of course it fails...

但是,它当然失败了......

Is this a way to bind some json string from a node property with cypher ?

这是一种从节点属性与cypher绑定一些json字符串的方法吗?

Thanks for your help

谢谢你的帮助

2 个解决方案

#1


4  

That's going against the principles of properties. Why not set the properties in the JSON metadata directly on the node?

这违背了财产原则。为什么不直接在节点上设置JSON元数据中的属性?

But to answer your question:

但要回答你的问题:

No, cypher has no knowledge about JSON.

不,cypher不了解JSON。

#2


4  

We treat the entire Node as a JSON blob. Since Neo4j doesn't support hierarchical properties, we flatten out the JSON into delimited property names on save and unflatten them on read. You can then form Cypher queries on (for example) property name "foo.bar.baz". The queries tend to look a bit funky because you'll need to quote them using single back quotes, but it works.

我们将整个Node视为JSON blob。由于Neo4j不支持分层属性,因此我们在保存时将JSON展平为分隔的属性名称,并在读取时将其展开。然后,您可以在(例如)属性名称“foo.bar.baz”上形成Cypher查询。查询往往看起来有点时髦,因为你需要使用单引号引用它们,但它有效。

#1


4  

That's going against the principles of properties. Why not set the properties in the JSON metadata directly on the node?

这违背了财产原则。为什么不直接在节点上设置JSON元数据中的属性?

But to answer your question:

但要回答你的问题:

No, cypher has no knowledge about JSON.

不,cypher不了解JSON。

#2


4  

We treat the entire Node as a JSON blob. Since Neo4j doesn't support hierarchical properties, we flatten out the JSON into delimited property names on save and unflatten them on read. You can then form Cypher queries on (for example) property name "foo.bar.baz". The queries tend to look a bit funky because you'll need to quote them using single back quotes, but it works.

我们将整个Node视为JSON blob。由于Neo4j不支持分层属性,因此我们在保存时将JSON展平为分隔的属性名称,并在读取时将其展开。然后,您可以在(例如)属性名称“foo.bar.baz”上形成Cypher查询。查询往往看起来有点时髦,因为你需要使用单引号引用它们,但它有效。