# Elasticsearch DSL: How to use QueryString + Time Range properly?

**URL:** https://discuss.elastic.co/t/elasticsearch-dsl-how-to-use-querystring-time-range-properly/93566
**Category:** Elasticsearch
**Created:** [July 18, 2017, 11:18am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-how-to-use-querystring-time-range-properly/93566 "2017-07-18T11:18:03Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![smlbiobot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smlbiobot/32/29622_2.png) [@smlbiobot](https://discuss.elastic.co/u/smlbiobot)
#### Post date: [July 18, 2017, 11:18am UTC](https://discuss.elastic.co/t/elasticsearch-dsl-how-to-use-querystring-time-range-properly/93566/1 "2017-07-18T11:18:03Z")

</div>

I’ve used the search.from\_dict() to construct my query and received my results correctly.

```
es = Elasticsearch()
s = Search(using=es, index="logstash-*")
s = s.from_dict({
    "query": {
        "query_string": {
            "query": "discord_event:message AND author.bot:false",
            "analyze_wildcard": True
        }
    }
})
response = s.execute()

```

However, I can’t figure out how the proper syntax for:

**Using QueryString**

I have tried:

```
qs = QueryString(query="discord_event:message AND author.bot:false")
s = query(qs)

```

Doesn’t work.

**Using time range to filter results**

I have tried:

```
s = s.filter('range', timestamp={'gte': 'now-5m', 'lt': 'now'})

```

This gave zero results. In Kibana I did the same search with time range and _am_ getting results.

Part of the reasons that I’d like to just use QS + time range is coz I am able to see my results in Kibana and would just like to plug in whatever I need after getting the correct results.

Any help would be greatly appeciated! I am using the Elasticsearch\_DSL Python library btw.

---

<div class="post-metadata">

### Author: ![smlbiobot](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smlbiobot/32/29622_2.png) [@smlbiobot](https://discuss.elastic.co/u/smlbiobot)
#### Post date: [July 18, 2017, 2:36pm UTC](https://discuss.elastic.co/t/elasticsearch-dsl-how-to-use-querystring-time-range-properly/93566/2 "2017-07-18T14:36:57Z")

</div>

Ok I have solved my own problem:

```
qs = QueryString(query="discord_event:message AND author.bot:false")
r = Range(** {'@timestamp': {'gte': 'now-7d', 'lt': 'now'}})
s.query(qs).query(r)

```

Please considered this issue closed.

---

<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 15, 2017, 2:36pm UTC](https://discuss.elastic.co/t/elasticsearch-dsl-how-to-use-querystring-time-range-properly/93566/3 "2017-08-15T14:36:59Z")

</div>

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