Elastic plugin that is called before insert?

Hi,

I want to create a plugin (or something similar) that inspects the data sent from logstash before it is inserted in elastic.
I found this documentation: https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-scripting.html#native-java-scripts

But how can I tell elastic that my code should be called before the insert occurs?
Is a plugin the correct way?

Take a look at ingest nodes. They are being developed right now, and will allows this exact functionality: