# Elastic Search via python gives wrong count

**URL:** <https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 9, 2019, 6:15pm UTC](https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173 "2019-12-09T18:15:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![forabraham](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@forabraham](https://discuss.elastic.co/u/forabraham)\
**Post date:** [December 9, 2019, 6:15pm UTC](https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173/1 "2019-12-09T18:15:05Z")

</div>

I’m new to python and I need to get connect to “Kibana” via python. we’re using Kibana 7.4.1. Requirement is to get the just the count (hits).

Due to some restriction I need to use Python 3.6 only. I’ve added the “ElasticSearch” & “ElasticSearch-dsl” library.

I’m able to get connected to the Kibana via the client, but I’m getting the wrong hits count.

Code:  
from elasticsearch import Elasticsearch  
from elasticsearch\_dsl import MultiSearch, Search  
from elasticsearch\_dsl.query import QueryString, Range, SimpleQueryString  
es = Elasticsearch(['host2', 'host2'], http\_auth=('usr', 'pass'), port=9200)  
s = Search(using=es, index='c\*')  
s.filter(SimpleQueryString(query="tags:prod AND severity:INFO AND service: finder AND msg:\* is processed"))  
s.filter(Range(\*\* {'@timestamp': {'gte': 'now-5m', 'lt': 'now'}}))  
response = s.execute()  
print("Got %d Hits:" % response['hits']['total']['value']) # Always coming as 1000 so this is wrong

Can I get some help on this please.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [December 11, 2019, 8:41am UTC](https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173/2 "2019-12-11T08:41:42Z")

</div>

See [https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-track-total-hits](https://www.elastic.co/guide/en/elasticsearch/reference/7.5/search-request-body.html#request-body-search-track-total-hits)

---

<div class="post-metadata">

**Author:** ![forabraham](https://avatars.discourse-cdn.com/v4/letter/f/c68b51/32.png) [@forabraham](https://discuss.elastic.co/u/forabraham)\
**Post date:** [December 11, 2019, 3:09pm UTC](https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173/3 "2019-12-11T15:09:08Z")

</div>

Thanks. I will check this and let you know.

---

<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:** [January 8, 2020, 3:09pm UTC](https://discuss.elastic.co/t/elastic-search-via-python-gives-wrong-count/211173/4 "2020-01-08T15:09:09Z")

</div>

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