graphaware / neo4j-to-elasticsearch

GraphAware Framework Module for Integrating Neo4j with Elasticsearch
261 stars 57 forks source link

Way to trigger reindexing when related edge/node changes #155

Closed jkcdarunday closed 3 years ago

jkcdarunday commented 5 years ago

We currently have the following node_mapping in our mapping.json file:

    {
      "condition": "hasLabel('Event')",
      "index": "company-events",
      "type": "_doc",
      "properties": {
        "creator": "query('MATCH (e:Event)-[c:IS_CREATED_BY]->(u:User) WHERE id(e)={id} RETURN u {.uuid, .email} as value')"
      }
    }

Right now, from what I understand, changes to properties of Event seem to propagate to elasticsearch. However, when User is changed or IS_CREATED_BY is remapped, it seems that these changes don't propagate to the properties.

Is there perhaps a way to trigger reindexing of another node when a relationship/node changes?

lpanichi commented 4 years ago

You can use a dedicated dummy property (such as last_elastic_indexing = DateTime()) on your node Event and do a SET last_elastic_indexing = DateTime() anytime you want to trigger queries. I think that it might be possible to add an apoc.trigger somehow to do this for you but I nerver tried it, if you find a way I'll hear it :)

HSan88 commented 4 years ago

same question :(

DaveClissold commented 4 years ago

There is a bit of a hacky way to do this. When you update the nodes have an update on the relationship

eg:

MATCH (e:Event)
SET e.something
WITH e
MATCH (e)-[c:IS_CREATED_BY]-()
SET c.counter = c.counter+1

This will trigger the relationship update on elasticsearch