Hi, I m trying to create an elastic query that should return all fields in each bucket using date histogram builder.
I have an index that has thresholdValue with a start date and end date of 2/3 months period. Now I want to retrieve thresholdValue in each month bucket.
elastic index doc:
{
"type":"GEN"
"startDate":"2022-01-01",
"endDate":"2022-02-28",
"thresholdValue":"1"
},
{
"type":"GEN"
"startDate":"2022-03-01",
"endDate":"2022-05-31",
"thresholdValue":"1.5"
}
Query:
POST /rating/_search
{
"aggs": {
"thresholdValue": {
"date_histogram": {
"field": "endDate",
"format": "yyyy-MM-dd",
"time_zone": "+05:30",
"calendar_interval": "1M",
"offset": 0,
"offset": 0,
"order": {
"_key": "asc"
},
"keyed": false,
"min_doc_count": 0,
"extended_bounds": {
"min": "2022-01-01",
"max": "2022-03-31"
}
},
"aggregations": {
"thresholdValue": {
"sum": {
"field": "thresholdValue"
}
}
}
}
}
}
Result I m getitng is:
"aggregations" : {
"thresholdValue" : {
"buckets" : [
{
"key_as_string" : "2022-01-01",
"key" : 1640975400000,
"doc_count" : 5,
"thresholdValue" : {
"value" : 1.0
}
},
{
"key_as_string" : "2022-02-01",
"key" : 1643653800000,
"doc_count" : 0,
"thresholdValue" : {
"value" : 0.0
}
},
{
"key_as_string" : "2022-03-01",
"key" : 1646073000000,
"doc_count" : 0,
"thresholdValue" : {
"value" : 1.5
}
}
]
}
}
}
My expecting result is 2nd bucket should also have thresholdValue 1.0 and the 4th bucket should have a value 1.5 as it matches under start and end date. but it is considering value in the 1st bucket only.
Thanks:)