I am using elastic search to count data, but I run into an issue that the result of using date histogram and the the result of using date range are different from each other.
Here is my query and its result using date histogram and group by date to count data.
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"range": {
"starttime": {
"from": 1686502800000,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"starttime": {
"from": null,
"to": 1688317199999,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "holdCall",
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"group_by_starttime": {
"date_histogram": {
"field": "starttime",
"calendar_interval": "1d",
"offset": 0,
"order": {
"_key": "asc"
},
"keyed": false,
"min_doc_count": 0
},
"aggregations": {
"count_id": {
"value_count": {
"field": "id.keyword"
}
}
}
}
}
}
{
"group_by_starttime": {
"buckets": [
{
"key": 1687564800000,
"doc_count": 4771,
"count_id": {
"value": 4771
}
},
{
"key": 1687651200000,
"doc_count": 25032,
"count_id": {
"value": 25032
}
}
]
}
}
As you can see in 25/06/2023 (1687651200000), the result is 25032.
Here is my query its result using date range to count data in 25/06/2023.
{
"query": {
"bool": {
"must": [
{
"bool": {
"must": [
{
"range": {
"starttime": {
"from": 1687626000000,
"to": null,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
},
{
"range": {
"starttime": {
"from": null,
"to": 1687712399999,
"include_lower": true,
"include_upper": true,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
{
"bool": {
"must_not": [
{
"exists": {
"field": "holdCall",
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"count_id": {
"value_count": {
"field": "id.keyword"
}
}
}
}
{
"count_id": {
"value": 29803
}
}
As you can see the result is 29803, and it is different from the result using date histogram.
How can I solve this issue, please? I did scour the Internet, but there is not anything found.