# Slow search response

**URL:** <https://discuss.elastic.co/t/slow-search-response/354501>\
**Category:** Elasticsearch\
**Created:** [March 1, 2024, 5:40am UTC](https://discuss.elastic.co/t/slow-search-response/354501 "2024-03-01T05:40:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![shivam\_raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivam_raj/32/122802_2.png) [@shivam\_raj](https://discuss.elastic.co/u/shivam_raj)\
**Post date:** [March 1, 2024, 5:40am UTC](https://discuss.elastic.co/t/slow-search-response/354501/1 "2024-03-01T05:40:47Z")

</div>

I have created a python appilication , to connect with es, there I am doing a document\_id search that is list  
es = Elasticsearch(  
CLOUD\_ID,  
http\_auth=(elastic\_user, ELASTIC\_PASSWORD)  
query = {  
"query": {  
"bool": {  
"must": [  
{  
"terms": {  
"documentId.keyword":document\_id  
}  
}  
]  
}  
}  
}  
result = es.search(index=ELASTICSEARCH\_INDEX, body=query)  
I am getting slow response around in 10 sec , for first time when we hit the same query again I am getting the fast response  
this making my appilication slow please can suggest to get fast response in first hits

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 1, 2024, 7:13am UTC](https://discuss.elastic.co/t/slow-search-response/354501/2 "2024-03-01T07:13:36Z")

</div>

Welcome!

Many factors but if you are seeing that in the context of integration tests, then that's "ok" I think.

Could you share:

- the exact query you are running? (Please execute it from the dev console)
- the response (I'd like to see the "took" value) for the 1st call
- the second response when you execute again

---

<div class="post-metadata">

**Author:** ![shivam\_raj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shivam_raj/32/122802_2.png) [@shivam\_raj](https://discuss.elastic.co/u/shivam_raj)\
**Post date:** [March 5, 2024, 4:07am UTC](https://discuss.elastic.co/t/slow-search-response/354501/3 "2024-03-05T04:07:36Z")

</div>

@dadoonet thank you

```auto
query = {
  "query": {
    "bool": {
      "must": [
        {
          "terms": {
            "documentId.keyword":document_id
          }
        }
      ]
    }
  }
        }
es = Elasticsearch(
CLOUD_ID,
http_auth=(elastic_user, ELASTIC_PASSWORD)
result = es.search(index=ELASTICSEARCH_INDEX, body=query)
hits = result['hits']['hits']

search_results = [hit['_source'] for hit in hits]

for i in range(len(search_results)):
            person_names = search_results[i]['personNames']
            parties = search_results[i]['parties']
            fileName = search_results[i]['fileName']
            contractDocumentId=search_results[i]['documentId']
            startDate=search_results[i]['startDate']
            expiryDate=search_results[i]['endDate']
            filesource=search_results[i]['source']
            sourceEmailId=search_results[i]['sourceEmailId']
            sourceDocLink=search_results[i]['sourceDocLink']

#document_id I am passing a list of document_id , currently this is in dev ,list size 0f 20-30 I am passing

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [March 5, 2024, 4:51am UTC](https://discuss.elastic.co/t/slow-search-response/354501/4 "2024-03-05T04:51:38Z")

</div>

Could you answer my questions?

> [@dadoonet](#):
>
> Could you share:
> 
> - the exact query you are running? (Please execute it from the dev console)
> - the response (I'd like to see the "took" value) for the 1st call
> - the second response when you execute again

Note that if you have a document id, you should use it as an \_id and then call the multiget API.

---

<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:** [April 2, 2024, 4:51am UTC](https://discuss.elastic.co/t/slow-search-response/354501/5 "2024-04-02T04:51:53Z")

</div>

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