title: how can I connect, from a flask app, to a remote elasticsearch cluster on aws?
body: <p>I have an elasticsearch cluster running on an EC2 server. I get a variety of different error mesages when I try to connect. </p>
  
  <p>Currently, in the elasticsearch.yml file all the transport items are commented out but I have tried:</p>
  
  <pre><code>network.host: 0.0.0.0
  and
  network.host: ec2-xx-xxx-xxx.aws.instance.com
  </code></pre>
  
  <p>In my flask app the code is as follows:</p>
  
  <pre><code>from datetime import datetime
  from flask import Flask, jsonify, request
  from elasticsearch import Elasticsearch
  
  #es = Elasticsearch()http://34.245.51.240/
  es = Elasticsearch(['ec2-34-xxx-xx-240.eu-west-1.compute.amazonaws.com','9200'])
  #es = Elasticsearch(['34.245.51.240','9200'])
  
  application = Flask(__name__)
  
  @application.route('/', methods=['GET'])
  def index():
      #results = es.get(index='contents', doc_type='title', id='my-new-slug')
      #return jsonify(results['_source'])
      doc = {
      'author': 'kimchy',
      'text': 'Elasticsearch: cool. bonsai cool.',
      'timestamp': datetime.now(),
      }
      res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
      print(res['res'])
      return res
  
  
  #application.run(port=5000, debug=True)
  if __name__ == '__main__':
      application.debug = True
      application.run()
  </code></pre>
  
  <p>I have googled multiple times and tried every possible configuration that I can find. </p>
  
  <p>What is the correct way to achieve this? </p>
  
  <p>Thank you. </p>