Hi @Stratoula_Kalafateli,
I am able to get the desired results by selecting Show empty buckets and Extends bounds between 0 to 23
curl works fine in dev_tools, although sometimes gives me #! Deprecation: Use of the joda time method [getHourOfDay()] is deprecated. Use [getHour()] instead. but same curl is not working from outside kibana i.e from server.
curl from kibana shows results properly
GET /access*/_search?pretty
{
  "aggs": {
    "2": {
      "histogram": {
        "script": {
          "source": "doc['@timestamp'].value.hourOfDay",
          "lang": "painless"
        },
        "interval": 1,
        "min_doc_count": 0,
        "extended_bounds": {
          "min": 0,
          "max": 23
        }
      }
    }
  },
  "size": 0,
  "_source": {
    "excludes": []
  },
  "stored_fields": [
    "*"
  ],
  "script_fields": {
    "custom_hour": {
      "script": {
        "source": "doc['@timestamp'].value.hourOfDay",
        "lang": "painless"
      }
    }
  },
  "docvalue_fields": [
    {
      "field": "@timestamp",
      "format": "date_time"
    }
  ],
  "query": {
    "bool": {
      "must": [],
      "filter": [
        {
          "bool": {
            "should": [
              {
                "match_phrase": {
                  "log.file.path": "/access-1.0/log/access_audit.log"
                }
              }
            ],
            "minimum_should_match": 1
          }
        },
        {
          "match_phrase": {
            "Request_URI": {
              "query": "\"/next2-isp/v1/*\""
            }
          }
        },
        {
          "range": {
            "@timestamp": {
              "format": "strict_date_optional_time",
              "gte": "2021-07-14T18:30:00.000Z",
              "lte": "2021-07-15T18:29:59.999Z"
            }
          }
        }
      ],
      "should": [],
      "must_not": []
    }
  }
}
same above curl (just by adding curl -u elastic:xxxx -XGET "http://localhost:9200/access*/_search?pretty" -H 'Content-Type: application/json' -d') is giving below error,
{
  "error" : {
    "root_cause" : [
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "doc[@timestamp].value.hourOfD ...",
          "    ^---- HERE"
        ],
        "script" : "doc[@timestamp].value.hourOfDay",
        "lang" : "painless"
      },
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "doc[@timestamp].value.hourOfD ...",
          "    ^---- HERE"
        ],
        "script" : "doc[@timestamp].value.hourOfDay",
        "lang" : "painless"
      },
      {
        "type" : "script_exception",
        "reason" : "compile error",
        "script_stack" : [
          "doc[@timestamp].value.hourOfD ...",
          "    ^---- HERE"
        ],
        "script" : "doc[@timestamp].value.hourOfDay",
        "lang" : "painless"
      },
      {
   .
   .
   .
   .
"type" : "search_phase_execution_exception",
    "reason" : "all shards failed",
    "phase" : "query",
    "grouped" : true,
    "failed_shards" : [
      {
        "shard" : 0,
        "index" : "access_server-2021.06.30",
        "node" : "oygWDlpVJN6lHTYnw",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "doc[@timestamp].value.hourOfD ...",
            "    ^---- HERE"
          ],
          "script" : "doc[@timestamp].value.hourOfDay",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "unexpected character [@].",
            "caused_by" : {
              "type" : "lexer_no_viable_alt_exception",
              "reason" : null
            }
          }
        }
      },
      {
        "shard" : 0,
        "index" : "access_server-2021.07.01",
        "node" : "oygWDlpV6lHTYnw",
        "reason" : {
          "type" : "script_exception",
          "reason" : "compile error",
          "script_stack" : [
            "doc[@timestamp].value.hourOfD ...",
            "    ^---- HERE"
          ],
          "script" : "doc[@timestamp].value.hourOfDay",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "unexpected character [@].",
            "caused_by" : {
              "type" : "lexer_no_viable_alt_exception",
              "reason" : null
            }
Thanks,