title: Filter data by day range in Elasticsearch using Python DSL
body: <p>I wrote this below method to filter data for last 8 days</p>
  <pre class="lang-py prettyprint-override"><code>def method_one(query) -&gt; Query:
      gte = (datetime.datetime.now() - datetime.timedelta(days=query)).date()
      lt = (datetime.datetime.now()).date()
      print(gte, lt)
      return Q(MultiMatch(
          query=filter(&quot;range&quot;, {&quot;lastModifiedDate&quot;: {&quot;gte&quot;: gte, &quot;lt&quot;: lt}}
                          ),
          fields=['lastModifiedDate']
      ))
  </code></pre>
  <p>I want to filter data based on the <code>lastModifiedDate</code> field by forming an Elasticsearch <code>Query</code> object in Python.
  For example if I give <strong>/lastModifiedDate=8</strong> (Rest API Call), it should return data by filtering for the last 8 days.</p>