# Getting timebased results in Elasticsearch using Python

**URL:** https://discuss.elastic.co/t/getting-timebased-results-in-elasticsearch-using-python/190071
**Category:** Elasticsearch
**Created:** [July 11, 2019, 4:37pm UTC](https://discuss.elastic.co/t/getting-timebased-results-in-elasticsearch-using-python/190071 "2019-07-11T16:37:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![elknewbee](https://avatars.discourse-cdn.com/v4/letter/e/8e7dd6/32.png) [@elknewbee](https://discuss.elastic.co/u/elknewbee)
#### Post date: [July 11, 2019, 4:37pm UTC](https://discuss.elastic.co/t/getting-timebased-results-in-elasticsearch-using-python/190071/1 "2019-07-11T16:37:05Z")

</div>

Hi All, I am newbie here and have a problem here getting correct results out of Elasticsearch. We have a pipeline where logs flow from Logstash into ES and then Kibana.  
The data is flows perfectly and we can see the visualizations on Kibana dashboard.  
But when I am trying to get a copy of the data that flows from ES to Kibana using a python script, I am getting historical data. I getting some logs from June.

Below is my query:

from elasticsearch import Elasticsearch  
es=Elasticsearch([{'host':'localhost','port':9200}])  
result = es.search(index='\*',body={  
"query": {  
"range" : {  
"date" : {  
"gte" : "now-15m/d",  
"lt" : "now/d"  
}  
}  
}  
})

the below query also gives wrong results:  
result1 = es.search(index='\*',body={'query':{'match\_all':{}}})

I did refer to this thread:

> [@How can i retrieve timebased index from elasticsearch using python script](https://discuss.elastic.co/t/how-can-i-retrieve-timebased-index-from-elasticsearch-using-python-script/147056):
>
> Hi Folks, I'm trying to retrieve time based events from elasticsearch using python script for few time intervals. could anyone here who can share the example to do it. using core api likes elasticsearch-py or elasticsearch\_dsl. Thanks, Yash M.

Please suggest.

---

<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: [August 8, 2019, 4:42pm UTC](https://discuss.elastic.co/t/getting-timebased-results-in-elasticsearch-using-python/190071/2 "2019-08-08T16:42:08Z")

</div>

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