I would recommend to check here with hasId(). Otherwise you would have to check for null? 

I assume elasticsearch generates here integer ids, so you could additionally check for integers > 0.