如何按时间范围过滤Go中的Elasticsearch结果?

I'm using olivere's v.5 elasticsearch library - https://godoc.org/github.com/olivere/elastic

Trying to do something similar to this post which uses the v.2 library - How to search in elasticsearch with Go filtering results by time frames

But 'NewRangeFilter' and 'NewFilteredQuery' are not available in v.5. There is a 'DateRange' API in v.5 (https://godoc.org/github.com/olivere/elastic#Aggregations.DateRange) that I can call from an Aggregation, but it takes in a string, so I don't know what I'm supposed to pass in.

This is what I've tried so far to build an aggregation. After that, I'm not sure what to pass into the DateRange function. I have an index called 'tmpindex' and type called 'user' and each document has a 'timestamp' property which is an integer.

timeline := elasticClient.NewTermsAggregation().Field("timestamp").Size(10).OrderByCountDesc()

    searchResult, err := elasticClient.Search().
        Index("tmpindex"). // search in index "tmpindex"
        Aggregation("timeline", timeline).
        From(0).Size(10).        // take documents 0-9
        Pretty(true).            // pretty print request and response JSON
        Do(context.Background()) // execute
    if err != nil {
        return err
    }

I think you're looking for Range Query.

You'd use it something like this...

query := elastic.NewBoolQuery().
    Filter(elastic.NewRangeQuery("timestamp").
        From(start).
        To(end))

Where start and end are time.Time values and "timestamp" is the name of your time field.

I should note that wrapping it in a filter of a Bool Query is just one way to use it. It can be used anywhere you can pass a Query.