Most likely your code but as I don't see it, I can't really tell.
Hard to help without knowing exactly what you are doing. ie, does your code run on the same machine which is running your code? What are elasticsearch logs? How do you create a client? Are you using a TransportClient or a RestClient? What is the error you are getting on the client?