Refactoring elasticsearch