0

Neo4j Version: 3.2.2

Operating System: Ubuntu 16.04

I use getDegree() function in mapping.json file, but the return would always be null; I'm using the dataset neo4j tutorial Movie/Actor dataset.

Output from elasticsearch request

mapping.json

{
  "defaults": {
    "key_property": "uuid",
    "nodes_index": "default-index-node",
    "relationships_index": "default-index-relationship",
    "include_remaining_properties": true
  },
  "node_mappings": [
    {
      "condition": "hasLabel('Person')",
      "type": "getLabels()",
      "properties": {
        "getDegree": "getDegree()",
        "getDegree(type)": "getDegree('ACTED_IN')",
        "getDegree(direction)": "getGegree('OUTGOING')",
        "getDegree('type', 'direction')": "getDegree('ACTED_IN', 'OUTGOING')",
        "getDegree-degree": "degree"
      }
    }
  ],
  "relationship_mappings": [
    {
      "condition": "allRelationships()",
      "type": "type",
    }
  ]
}

Also if I use isOutgoing(), isIncoming(), otherNode function in relationship_mappings properties part, elasticsearch would never load the relationship data from neo4j. I think I probably have some misunderstanding of this sentence only when one of the participating nodes "looking" at the relationship is provided on this page https://github.com/graphaware/neo4j-framework/tree/master/common#inclusion-policies

mapping.json

{
  "defaults": {
    "key_property": "uuid",
    "nodes_index": "default-index-node",
    "relationships_index": "default-index-relationship",
    "include_remaining_properties": true
  },
  "node_mappings": [
    {
      "condition": "allNodes()",
      "type": "getLabels()"
    }
  ],
  "relationship_mappings": [
    {
      "condition": "allRelationships()",
      "type": "type",
      "properties": {
        "isOutgoing": "isOutgoing()",
        "isIncomming": "isIncomming()",
        "otherNode": "otherNode"
      }
    }
  ]
}

BTW, is there any page that list all of the functions that we can use in mapping.json? I know two of them

  1. github.com/graphaware/neo4j-framework/tree/master/common#inclusion-policies
  2. github.com/graphaware/neo4j-to-elasticsearch/blob/master/docs/json-mapper.md but it seems there are more, since I can use getType(), which hasn't been listed in any of the above pages.

Please let me know if I can provide any further help to solve the problem

Thanks!

Zhenshan Jin
  • 379
  • 3
  • 10

1 Answers1

2

The getDegree() function is not available to use, in contrary to getType(). I will explain why :

When the mapper (the part responsible to create a node or relationship representation as ES document ) is doing its job, it receive a DetachedGraphObject being a detached node or relationship.

The meaning of detached is that it is happening outside of a transaction and thus query operations are not available against the database anymore. The getType() is available because it is part of the relationship metadata and it is cheap, however if we would want to do the same for getDegree() this can be seriously more costly during the DetachedObject creation (which happen in a tx) depending on the number of different types etc.

This is however something we are working on, by externalising the mapper in a standalone java application coupled with a broker like kafa, rabbit,.. between neo and this app. We would not, however offer the possibilty to requery the graph in the current version of the module as it can have serious performance impacts if the user is not very careful.

As last, the only suggestion I can give you is to keep a property on your node with the updates of degrees you need to replicate to ES.

UPDATE

Regarding this part of the documentation :

For Relationships only when one of the participating nodes "looking" at the relationship is provided:

This is used only when not using the json definition, so you can use one or the other. the json definition has been added later as addition and both cannot be used together.

For answering this part, it means that the nodes of the incoming or outgoing side, depending on the definition, should be included in the inclusion policy for nodes, like hasLabel('Employee') || hasProperty('form') || getProperty('age', 0) > 20 . If you have an allNodes policy then it is fine.

Christophe Willemsen
  • 19,399
  • 2
  • 29
  • 36
  • Thank you for the detailed answer, Christophe! one more question, what does `only when one of the participating nodes "looking" at the relationship is provided` mean in https://github.com/graphaware/neo4j-framework/tree/master/common#inclusion-policies mean? I want to use isIncoming()/isOutgoing() function for relationship and how can I provide `the nodes that "looking" at the relationship` – Zhenshan Jin Aug 05 '17 at 20:55
  • Thanks! now I understand it – Zhenshan Jin Aug 06 '17 at 01:28
  • Is creating a property on your node with updates of degrees you need in ES still the best practice approach today? – N Meibergen Jan 20 '20 at 06:14
  • It is still yes, and easily doable with triggers such as GraphAware neo4j-triggers or APOC triggers – Christophe Willemsen Jan 20 '20 at 10:36
  • Indeed I tried doing so with the APOC trigger however this did not trigger a Bulk operation in the GraphAware-ElasticSearch plugin, could you look at this related questions here: https://stackoverflow.com/questions/59897342/apoc-trigger-transaction-not-resulting-in-a-graphaware-elasticsearch-bulk-operat – N Meibergen Jan 24 '20 at 13:26