# Querying elastic with Python API

**URL:** <https://discuss.elastic.co/t/querying-elastic-with-python-api/217922>\
**Category:** Elasticsearch\
**Created:** [February 5, 2020, 7:34am UTC](https://discuss.elastic.co/t/querying-elastic-with-python-api/217922 "2020-02-05T07:34:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sandeepduppalli](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sandeepduppalli/32/47290_2.png) [@sandeepduppalli](https://discuss.elastic.co/u/sandeepduppalli)\
**Post date:** [February 5, 2020, 7:34am UTC](https://discuss.elastic.co/t/querying-elastic-with-python-api/217922/1 "2020-02-05T07:34:06Z")

</div>

Hi Team

I have been given assignment of developing a Python API for connecting Elasticsearch and get the things that are requested. For this I have used Python flask. I am trying to test it with Postman. But I am failing to get the desired output. I am running Flask on Private IP address and Elasticsearch on Localhost. When I provide index name and JSON query in code I am able to fetch the details. When I pass a value of that index I am able to fetch Index details .But the same details if I provide in Postman I am getting below Error. How can I pass the JSON from Postman to Python-Flask Code as a Variable and what should be the URL route in flask application. Is it should be like \<\>/index/type/\_search...?? Please give me some infer.

File "local/bin/elasticapi/elastic/elastic1.py", line 14, in index  
elk = es.search(bodyin)  
File "/.local/bin/elasticapi/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 84, in \_wrapped  
return func(\*args, params=params, \*\*kwargs)  
File "/.local/bin/elasticapi/lib/python2.7/site-packages/elasticsearch/client/ **init**.py", line 1548, in search  
"GET", \_make\_path(index, doc\_type, "\_search"), params=params, body=body  
File "/.local/bin/elasticapi/lib/python2.7/site-packages/elasticsearch/transport.py", line 318, in perform\_request  
body = self.serializer.dumps(body)  
File "/.local/bin/elasticapi/lib/python2.7/site-packages/elasticsearch/serializer.py", line 54, in dumps  
raise SerializationError(data, e)  
SerializationError: (\<Response 43 bytes [200 OK]\>, TypeError("Unable to serialize \<Response 43 bytes [200 OK]\> (type: \<class 'flask.wrappers.Response'\>)",))

Code I am using:

from flask import Flask,render\_template,request  
from elasticsearch import Elasticsearch

elasticapp = Flask( **name** )  
es = Elasticsearch()

@elasticapp.route('/',methods=["GET","POST"])  
def index():

```
q = request.args.get("q")

if q is not None:
    resp=es.search(index=testindex, body= {'query':{'match':{'Name': q}}})
    return render_template("index.html",q=q,response=resp)

return render_template('index.html')

```

## if **name** == " **main**": elasticapp.run(host= '\<Private\_IP\>',debug=True,port=8000)

For the above code If I pass the value of 'q' i can fetch Index details.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 4, 2020, 7:34am UTC](https://discuss.elastic.co/t/querying-elastic-with-python-api/217922/2 "2020-03-04T07:34:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
