Plugin to override indexing/deleting

Hi!
I'd like to write a ES plugin which allow me to write an additional file containing information about a document.

I'm currently indexing document with spatial boundaries(polygons). for each document i'm indexing, i'd like to insert this boundary in a custom R-Tree file (and remove it from the file when the document is deleted).
I used to do it directly with lucene, but now we move to ElasticSearch for cloud purpose.

I already have an ES plugin adding a Lucene Filter which read the file and perform a spatial search.

What i want is i to write my R-tree file for each shard, containing the spatial boundary of all the document in this shard,
In order to distribute my spatial search on each shard. I also like that when a shard is replicated, my file be replicated too.

I explored a lot of custom plugins and didn't find any way to do that. how can i :
override the indexWriter ?
add additional code at index/remove time?

thank's in advance
Guilhem Legal