I think there is no event for unpublishing a content. You might want to use IPublishedStateAssessor or FilterContentForVisitor to check if a content should be gotten from the index.
One approach I've taken/seen is to use the Publish event, but with one more check for StopPublish date -- something like this, in the PublishedContent event:
if (content.StopPublish.HasValue && content.StopPublish <= DateTime.Now)
...then it's expired
Given something can become unpublished when the stop publish date goes from in the future to in the past, there will not be an event that happens immediately in the CMS editor code. You're better off making sure your elastic search queries only include content where the Stop Publish Date is null or in the future and maybe add a Scheduled Job that removes recently expired content from your Elastic Search index.
Hi all good Opti people!
I wonder if it's any way in Optimizely that you can hook up lik ContentEvent- Publishing but for un-publishing content?
Why I'm asking?
I have one Elasticsearch index that need to be updated when a editor have schedule to unpublish a page and when the unpublishing and when the time has come it should remove the content from the index. I will not that we should have an schedulejobb that reindex the whole site when something like this happends.
Have you a clue how i in a best way kan solve this issue?
Great regards
MIkael