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

**URL:** <https://discuss.elastic.co/t/java-resthighlevelclient-offset-stripped-from-query-for-datehistogram-in-composite-aggregation/261259>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [January 15, 2021, 12:51pm UTC](https://discuss.elastic.co/t/java-resthighlevelclient-offset-stripped-from-query-for-datehistogram-in-composite-aggregation/261259 "2021-01-15T12:51:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jselberg](https://avatars.discourse-cdn.com/v4/letter/j/dec6dc/32.png) [@jselberg](https://discuss.elastic.co/u/jselberg)\
**Post date:** [January 15, 2021, 12:51pm UTC](https://discuss.elastic.co/t/java-resthighlevelclient-offset-stripped-from-query-for-datehistogram-in-composite-aggregation/261259/1 "2021-01-15T12:51:25Z")

</div>

Hi,

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:

```auto
BoolQueryBuilder filterQuery = boolQuery()
        .filter(termQuery("id.keyword", id))
        .filter(rangeQuery("timestamp").gte(queryTimePeriod.getStartTime()).lt(queryTimePeriod.getEndTime()));

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

DateHistogramValuesSourceBuilder dateHistogram = new DateHistogramValuesSourceBuilder("period_start")
        .field("timestamp")
        .timeZone(ZoneOffset.UTC)
        .format("yyyy-MM-dd'T'HH:mm:SS'Z'")
        .offset(-86400000) // -1 day in ms
        .calendarInterval(DateHistogramInterval.WEEK)
        .order(SortOrder.DESC);

CompositeAggregationBuilder compositeAggregationBuilder = AggregationBuilders.composite("avg_over_time", List.of(idTerm, nameTerm, dateHistogram))
        .subAggregation(AggregationBuilders.avg("cAvg").field("c"))
        .size(MAX_RESULTS);

SearchSourceBuilder searchSource = new SearchSourceBuilder()
        .aggregation(compositeAggregationBuilder)
        .query(filterQuery)
        .size(0);

SearchResponse response = client.search(new SearchRequest("indexToSearch").source(searchSource)

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 12, 2021, 12:51pm UTC](https://discuss.elastic.co/t/java-resthighlevelclient-offset-stripped-from-query-for-datehistogram-in-composite-aggregation/261259/2 "2021-02-12T12:51:27Z")

</div>

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