Zhenshan Jin
Zhenshan Jin

Reputation: 419

getDegree()/isOutgoing() funcitons don't work in graphAware/neo4j-to-elasticsearch mapping.json

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!

Upvotes: 0

Views: 89

Answers (1)

Christophe Willemsen
Christophe Willemsen

Reputation: 20185

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.

Upvotes: 2

Related Questions