Logstash - Elasticsearch filter unable to fetch start events

I'm trying to replicate the exact use case for elasticsearch filter detailed in the docs

My output is also the same elasticsearch server.

I need to compute the time duration between two events. And the end events appear @ <10ms after the start events.

What I'm observing is logstash is failing to fetch the start event for some end events.
My guess is, such start events are still buffered when logstash looks for them in ES.
I have tried setting the flush_size property to a low value in the output filter, this only helped a little. There were fewer "miss" cases when its configured to a low value. I'd tried setting it to 1 too, just to confirm this. There were still a few exit events that couldnt find their entry events.

Is there anything else that I should look for, that could possibly be causing the issue, as setting flush_size to too low a value didnt help and doesnt look like an optimal solution either.

Here's my logstash config :

          elasticsearch {
            hosts => ["ES_SERVER_IP:9200"]
            query => "event:ENTRY AND id:%{[id]}"
            fields => {"log-timestamp" => "started"}
            sort => ["@timestamp:desc"]
          ruby {
            code => "event['processing_time'] = event['log-timestamp'] - event['started']"