Elasticsearch: Aggregations request timezone field not working

Elasticsearch Version: 7.7.0v
Rest client Vesion: 7.7.0v

The query created by Postman and the request created by QueryBuilder are the same, but the TimeZone field is not applied to java requests.

here is request target mapping info

"timeArchived": {
                "type": "date",
                "format": "yyyy-MM-dd HH:mm:ss||epoch_millis"
            }

here is java request source

SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
        BoolQueryBuilder query = QueryBuilders.boolQuery();
        sourceBuilder.trackTotalHits(true);
        sourceBuilder.size(0);
        sourceBuilder.query(query);
        RangeQueryBuilder rangeQuery = QueryBuilders.rangeQuery("timeArchived").timeZone("Asia/Seoul").gte(sTime).lte(eTime);
        query.filter(rangeQuery);
        query.must(QueryBuilders.termQuery("domain", domain));
        
        sourceBuilder.aggregation(AggregationBuilders.dateHistogram("mailDate").field("timeArchived").fixedInterval(DateHistogramInterval.hours(1)).timeZone(ZoneId.of("ROK")));
        
        SearchRequest request = new SearchRequest();
        request.source(sourceBuilder);
        SearchResponse response = null;
        try {
            response = client.search(request, RequestOptions.DEFAULT);
        } catch (IOException e) {
            e.printStackTrace();
        }

here is created request query. java builder request and postman request same query.

{
   "size":0,
   "query":{
      "bool":{
         "must":[
            {
               "term":{
                  "domain":{
                     "value":"test.com",
                     "boost":1.0
                  }
               }
            }
         ],
         "filter":[
            {
               "range":{
                  "timeArchived":{
                     "from":"2020-09-18 04:00:00",
                     "to":"2020-09-18 10:09:46",
                     "include_lower":true,
                     "include_upper":true,
                     "time_zone":"Asia/Seoul",
                     "boost":1.0
                  }
               }
            }
         ],
         "adjust_pure_negative":true,
         "boost":1.0
      }
   },
   "track_total_hits":2147483647,
   "aggregations":{
      "mailDate":{
         "date_histogram":{
            "field":"timeArchived",
            "time_zone":"ROK",
            "fixed_interval":"1h",
            "offset":21600000,
            "order":{
               "_key":"asc"
            },
            "keyed":false,
            "min_doc_count":0
         }
      }
   }
}

but request response not same. java request timeZone option not working.

this postman request result timeZone option worked well.

{
    "took": 484,
    "timed_out": false,
    "_shards": {
        "total": 1,
        "successful": 1,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 177,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "mailDate": {
            "buckets": [
                {
                    "key_as_string": "2020-09-18 04:00:00",
                    "key": 1600369200000,
                    "doc_count": 8
                },
                {
                    "key_as_string": "2020-09-18 05:00:00",
                    "key": 1600372800000,
                    "doc_count": 16
                },
                {
                    "key_as_string": "2020-09-18 06:00:00",
                    "key": 1600376400000,
                    "doc_count": 4
                },
                {
                    "key_as_string": "2020-09-18 07:00:00",
                    "key": 1600380000000,
                    "doc_count": 10
                },
                {
                    "key_as_string": "2020-09-18 08:00:00",
                    "key": 1600383600000,
                    "doc_count": 17
                },
                {
                    "key_as_string": "2020-09-18 09:00:00",
                    "key": 1600387200000,
                    "doc_count": 98
                },
                {
                    "key_as_string": "2020-09-18 10:00:00",
                    "key": 1600390800000,
                    "doc_count": 24
                }
            ]
        }
    }
}

but java request timeZone option not working. response is UTC time.

{
   "took":918,
   "timed_out":false,
   "_shards":{
      "total":3,
      "successful":3,
      "skipped":0,
      "failed":0
   },
   "hits":{
      "total":{
         "value":223,
         "relation":"eq"
      },
      "max_score":null,
      "hits":[
         
      ]
   },
   "aggregations":{
      "date_histogram#mailDate":{
         "buckets":[
            {
               "key_as_string":"2020-09-17T19:00:00.000Z",
               "key":1600369200000,
               "doc_count":8
            },
            {
               "key_as_string":"2020-09-17T20:00:00.000Z",
               "key":1600372800000,
               "doc_count":16
            },
            {
               "key_as_string":"2020-09-17T21:00:00.000Z",
               "key":1600376400000,
               "doc_count":4
            },
            {
               "key_as_string":"2020-09-17T22:00:00.000Z",
               "key":1600380000000,
               "doc_count":10
            },
            {
               "key_as_string":"2020-09-17T23:00:00.000Z",
               "key":1600383600000,
               "doc_count":17
            },
            {
               "key_as_string":"2020-09-18T00:00:00.000Z",
               "key":1600387200000,
               "doc_count":98
            },
            {
               "key_as_string":"2020-09-18T01:00:00.000Z",
               "key":1600390800000,
               "doc_count":70
            }
         ]
      }
   }
}

How do I set timezone in java?

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