4

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 :

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(movie.Metadata).RatingPress

But, of course it fails...

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

Thanks for your help

Fred
  • 117
  • 1
  • 8

2 Answers2

4

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

But to answer your question:

No, cypher has no knowledge about JSON.

Werner Kvalem Vesterås
  • 10,226
  • 5
  • 43
  • 50
  • Actually metadata may contain RatingPress for some nodes but not for other ones so I am thinking about a way to add addtionals info to a node like metadata into a single raw string. – Fred Jan 13 '13 at 16:30
  • So I guess I have to generate Json object based with some RatingPress property if I have got one and without the property if I don't have RatingPress for a kind of node. – Fred Jan 13 '13 at 16:34
  • 1
    Properties are optional and there is no schema, so you can add properties as you like and cypher has some ways of checking for properties, like `has(n.RatingPress)` or `n.RatingPress? = "foo"` (also true if prop is not there) or `n.RatingPress! > 10` (requires the prop) – Michael Hunger Jan 16 '13 at 14:04
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.

bjlevine
  • 873
  • 1
  • 9
  • 23
  • Is the flattening/unflattening something you do in code, or could this be done in a server extension? – Arjan Nov 05 '14 at 21:49
  • 1
    The (un)flattening is done in our server-side code which then calls the Neo4j REST API to do queries/persistence However, I suppose it'd be possible to do this in a server extension depending on your use-case. If you're accessing Neo4j via its REST API, then you could implement your own REST methods as a server extension and do the (un)flattening there. If you're embedding Neo4j and using the Java API, you might be able to do this in a TransactionEventHandler. – bjlevine Nov 07 '14 at 15:28