Anybody have an example of a watcher that will monitor lets say the changes in prices for a specific product.
Hey,
this highly depends on your data model. Currently, there is no such thing as changes stream in Elasticsearch, is planned to be done though. Also keep in mind, that there are no old revisions kept around in Elasticsearch, so you have to add this kind of functionality inside of your documents.
So, how could you do this currently? You could index your products including a last_changed
field, and execute queries to only include documents that have been changed in the last XYZ minutes. Now you still need to search for a changed price. If you keep the price history in the document itself, you could compare current and former prices.
You could also simplify this and have price_last_changed
field and just include the last price, if you can cover this in your application indexing logic - then this suddenly boils down to a single query to be registered.
Maybe there is a different solution based on your data model which you want to extend on.
--Alex
I found this question as I am trying to do the same thing, but after reading this I had the idea that when you register the watcher you first run a query to get the current value of that field. Then you simply put that value in a:
{ "bool": { "must_not": { "term": { "<field>": <curr_value> }}}}
The clunky bit here is that the watcher needs to be updated with a new value every time the watch gets hit. For me, thats not an issue because one of the actions is a webhook back to the app that created the watch in the first place.