ElasticSearch code refactory