def new_index(): # Try create an index, # First check if pipeline exists # Connect to our cluster es = Elasticsearch([{'host': 'localhost', 'port': '9200'}]) exists = es.exists_source(index='apsys', doc_type='test') if exists: json_response = app.response_class( response='', status=418, mimetype='application/json' ) return json_response else: data = request.get_json() response = es.index(index='apsys', doc_type=data['doc_type'], body={'data': data['data']}) print(response) jsonResponse = app.response_class( response=json.dumps(response), status=200, mimetype='application/json' ) return jsonResponse