Registering node neighborhood in elastic document

graphaware

(Leonard Panichi) #1

Hello,
I wonder if there is anyway to register the neighborhood of a node in an elastic document ?
For instance let's take two nodes:
(a:LabelA{prop1a:"p1a", prop2a:"p2a"})
and
(b:LabelB{prop1b:"p1b", prop2b:"p2b"})
connected in this way :
(a)-[:see]->(b)
I wish to insert a document in elasticsearch that register the first property of a, the second property of b and their relation (see).
the result would be something like :
{
label: "LabelA",
prop1a:"p1a",
see :{
label:"LabelB",
prop2b:"p2b"
}
}

Can i do this with for instance graphaware ?


(Leonard Panichi) #2

ok, allow me to answer myself.
First please see the documentation of


and

Please note that this documentation lakes a RETURN statement in the query attached to the "keywords" field
That being said, I think that several strategies are possible, here is what I did and tested.

First, please note that I use my own uuid on the LabelA nodes. Here is my config for neo4j.conf

dbms.unmanaged_extension_classes=com.graphaware.server=/graphaware
com.graphaware.runtime.enabled=true
com.graphaware.module.ES.2=com.graphaware.module.es.ElasticSearchModuleBootstrapper
com.graphaware.module.ES.uri=localhost
com.graphaware.module.ES.port=9200
com.graphaware.module.ES.protocol=http
com.graphaware.module.ES.keyProperty=uuid
com.graphaware.module.ES.retryOnError=false
com.graphaware.module.ES.queueSize=10000
com.graphaware.module.ES.reindexBatchSize=2000
com.graphaware.module.ES.bulk=true
com.graphaware.module.ES.initializeUntil=0
com.graphaware.module.ES.mapping=com.graphaware.module.es.mapping.JsonFileMapping
com.graphaware.module.ES.file=mapping.json

and the mapping.json :

{
  "defaults": {
    "key_property": "uuid",
    "nodes_index": "indexed-by-mapping",
    "include_remaining_properties": false
  },
  "node_mappings": [
    {
      "condition": "hasLabel('LabelA')",
      "type": "persons",
      "properties": {
        "name": "getProperty('prop1a')",
        "dummy": "getProperty('dummy')",
        "see": "query('MATCH (n) WHERE id(n) = {id} MATCH (n)-[:see]->(m:LabelB) RETURN collect(m.prop1b) AS value')"
      }
    }
  ]
}

Now, inserting a LabelA node and connecting it in a later query to a LabelB node won't trigger the push to elastic if none of the properties imported in elastic are changed. this is why the dummy property should be modified any time you want to actualize the "see" field.
Hence the cypher query:

MATCH (n:LabelA{uuid:<use the requested uuid>})
SET n.dummy = n.dummy+1
CREATE (n)-[:see]->(m:LabelB{prop1b:"third"})

This is the core of the answer.
I think another solution may be based on relationship mapping but this solution is good enough for me.
Anyway congrats for the framework and the plugin, it's very useful !