add main for running plugin against another elasticsearch instance
some optimizations and refactoring