Java RestHighLevelClient: Offset stripped from query for Datehistogram in Composite aggregation


We're trying to aggregate some data on a weekly basis, but we would like to adjust the calculation of weeks so that the weeks starts on Sundays instead.

We've tried using the offset() operation from the DateHistogramValuesSourceBuilder to achieve this, when building CompositeAggregation.

But the query that gets generated always seems to strip/not include the offset field defined from the client, and the resulting buckets starts on Mondays.

Any ideas why we get this behaviour? Or suggestions for alternatives solutions to achieve the behaviour we want?

Client version: 7.6.2
Server version: 7.6.2

Example code below:

BoolQueryBuilder filterQuery = boolQuery()
        .filter(termQuery("id.keyword", id))

TermsValuesSourceBuilder versionTerm = new TermsValuesSourceBuilder("version").field("version.keyword");
TermsValuesSourceBuilder nameTerm = new TermsValuesSourceBuilder("name").field("name.keyword");

DateHistogramValuesSourceBuilder dateHistogram = new DateHistogramValuesSourceBuilder("period_start")
        .offset(-86400000) // -1 day in ms

CompositeAggregationBuilder compositeAggregationBuilder = AggregationBuilders.composite("avg_over_time", List.of(idTerm, nameTerm, dateHistogram))

SearchSourceBuilder searchSource = new SearchSourceBuilder()

SearchResponse response = SearchRequest("indexToSearch").source(searchSource)

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