def get_last_study_date(repository_url, interval):
    """ Retrieve the last study_creation_date of the item corresponding
    to given repository from the study index.
    """
    query_last_study_date = (
        """
    {
        "size": 0,
        "aggs": {
            "1": {
                "max": {
                    "field": "study_creation_date"
                }
            }
        },
        "query": {
            "bool": {
                "filter": [{
                    "term": {
                        "origin.keyword": "%s"
                    }
                },{
                    "term":{
                        "interval_months": "%s"
                    }
                }]
            }
        }
    }
    """
         % (repository_url, interval))
    return query_last_study_date
