Announcement Announcement Module
Collapse
No announcement yet.
Cypher Query Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Cypher Query

    Hello Graphistas,

    maybe one of you cypher wizards can get me started on creating a query. We've got some "entity" nodes that are connected to PropertyValue nodes. These PropertyValue nodes are connected to PropertyDefinition nodes. Basically this means we've externalized the Neo4j properties into external nodes; so the name or address of an entity lies in a separate node:

    Attachment


    Now I'm a bit clue less what a cypher query would look like to get all nodes that have certain name and certain address.

    Any ideas/hints?

    Regards,
    Andi
    Attached Files
    Last edited by zaphod748; Mar 26th, 2012, 10:51 AM. Reason: PNG to JPG conversion sucks

  • #2
    Code:
    start reference=node(0) 
    match reference-[:DEVICE]->device-[:HAS_PROPERTY]->prop_def, 
    device-[:DEVICE]->instance-[:HAS_PROPERTY_VALUE]->property<-[:IS_OF_TYPE]-prop_def 
    where prop_def.name="entity.device.address" and property.value ={address} 
      or prop_def.name="entity.device.name" and property.value ={name}
    return instance
    See: http://docs.neo4j.org/chunked/milest...uery-lang.html

    Comment


    • #3
      Hi Michael,

      that's almost want I wanted :-)

      Let's say I've got:

      Device { name: A, address: A}
      Device { name: B, address: A}

      Now I want to filter on the prop_def.name='entity.device.name' and prop_def.name='entity.device.name'. Your solution would return both devices but I want just devices named 'A' with address 'A'.

      Regards,
      Andi

      Comment


      • #4
        So you would use *and* instead of *or* (btw you mistyped one address with name)

        Comment


        • #5
          I still don't get. Using *and* doesn't return any rows. Running the query with OR and slightly modified ( the property definition nodes are named different and also the relation [IS_OF_TYPE] goes actually from (PropertyValue)-->(PropertyDefinition) ):

          start reference=node(0) match reference-[EVICE]->device-[:HAS_PROPERTY]->prop_def, device-[EVICE]->instance-[:HAS_PROPERTY_VALUE]->property-[:IS_OF_TYPE]->prop_def where prop_def.name='device.address' and property.value='A' or prop_def.name='entity.name' and property.value='A' return instance.uuid, prop_def.name, property.value

          +----------------------------------------------------------------------------+
          | instance.uuid | prop_def.name | property.value |
          +----------------------------------------------------------------------------+
          | "46c4e484-e280-491d-a76b-740438c4d026" | "entity.name" | "A" |
          | "0db93348-0167-4a81-9230-e9405e8c9e4e" | "device.address" | "A" |
          | "46c4e484-e280-491d-a76b-740438c4d026" | "device.address" | "A" |
          +----------------------------------------------------------------------------+
          3 rows, 497 ms

          Comment


          • #6
            I think what you are looking for is something like this:

            Code:
            start reference=node(0) 
            match reference-[:DEVICE]->device-[:HAS_PROPERTY]->prop_def, 
                device-[:DEVICE]->instance-[:HAS_PROPERTY_VALUE]->addres_prop<-[:IS_OF_TYPE]-address_prop_def,
                device-[:DEVICE]->instance-[:HAS_PROPERTY_VALUE]->name_prop<-[:IS_OF_TYPE]-name_prop_def 
            where address_prop_def="entity.device.address" and addres_prop.value ={address} 
              and name_prop_def.name="entity.device.name" and name_prop.value ={name}
            return instance
            I've seen this done lots of times with SQL databases, and while it's interesting, your performance will suffer badly from the added abstraction layer you just created.

            Andrés

            Comment


            • #7
              That's exactly what I was looking for!

              Yes this kind of "normalization" comes with a prize, but it also makes it possible to have different versions of the nodes property values and such kind of things.

              Thanks a lot!
              Andi

              Comment


              • #8
                Just for those that are also new to Cypher; the query above (and of course others as well) can be quite easily generated during runtime using Querydsl.

                Comment


                • #9
                  Originally posted by zaphod748 View Post
                  Just for those that are also new to Cypher; the query above (and of course others as well) can be quite easily generated during runtime using Querydsl.
                  Huh? I didn't see any support for Neo4j on Querydsl. Just for JPA, JDO and Mongo.

                  Mark

                  Comment


                  • #10
                    The CypherDSL project (which is supported by SDN) has support for QueryDSL and so has SDN.

                    There is also a CypherDSLRepository-Test for that.

                    Comment

                    Working...
                    X