Filter data by day range in Elasticsearch using Python DSL

I wrote this below method to filter data for last 8 days

def method_one(query) -> Query:
    gte = (datetime.datetime.now() - datetime.timedelta(days=query)).date()
    lt = (datetime.datetime.now()).date()
    print(gte, lt)
    return Q(MultiMatch(
        query=filter("range", {"lastModifiedDate": {"gte": gte, "lt": lt}}
                        ),
        fields=['lastModifiedDate']
    ))

I want to filter data based on the lastModifiedDate field by forming an Elasticsearch Query object in Python.
For example if I give /lastModifiedDate=8 (Rest API Call), it should return data by filtering for the last 8 days.

Source: Python-3x Questions

LEAVE A COMMENT