Elastic Search via python gives wrong count

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.

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

Thanks. I will check this and let you know.

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