Unauthorized User Error and Script Execution Issues During Kibana Setup with Elasticsearch 7.17.13

I am encountering multiple errors while setting up Kibana with Elasticsearch version 7.17.13. The primary issues are:

  1. Unauthorized User error with the fleet plugin, indicating a failure in setting up central management of agents.
  2. Repeated errors in taskManager related to script execution, specifically "cannot execute scripts using [number_sort] context."

ES & Kibana Version: 7.17.13

Note: I have provided elasticsearch username and password in Kibana.yml.

Here are some specific log entries:

overEnhanced,dataVisualizer,ml,uptime,securitySolution,infra,upgradeAssistant,monitoring,logstash,enterpriseSearch,apm,savedObjectsManagement,indexPatternManagement]
  log   [20:11:16.486] [info][monitoring][monitoring][plugins] config sourced from: production cluster
  log   [20:11:17.633] [info][server][Kibana][http] http server running at http://localhost:5601
  log   [20:11:17.681] [info][kibana-monitoring][monitoring][monitoring][plugins] Starting monitoring stats collection
  log   [20:11:17.720] [info][chromium][plugins][reporting] Browser executable: C:\Kibana\kibana-7.17.13\x-pack\plugins\reporting\chromium\chrome-win\chrome.exe
  log   [20:11:17.747] [warning][plugins][securitySolution] Unable to verify endpoint policies in line with license change: failed to fetch package policies: Unauthorized User
  log   [20:11:17.748] [error][fleet][plugins] Setup for central management of agents failed.
  log   [20:11:17.749] [error][fleet][plugins] ResponseError: Unauthorized User
    at onBody (C:\Kibana\kibana-7.17.13\node_modules\@elastic\elasticsearch\lib\Transport.js:367:23)
    at IncomingMessage.onEnd (C:\Kibana\kibana-7.17.13\node_modules\@elastic\elasticsearch\lib\Transport.js:291:11)
    at IncomingMessage.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  meta: {
    body: 'Unauthorized User',
    statusCode: 401,
    headers: {
      'www-authenticate': 'Basic realm="ESSearch"',
      'content-type': 'text/plain; charset=UTF-8',
      'content-length': '17'
    },
    meta: {
      context: null,
      request: [Object],
      name: 'elasticsearch-js',
      connection: [Object],
      attempts: 0,
      aborted: false
    }
  },
  isBoom: true,
  isServer: false,
  data: null,
  output: {
    statusCode: 401,
    payload: {
      statusCode: 401,
      error: 'Unauthorized',
      message: 'Unauthorized User'
    },
    headers: {}
  },
  [Symbol(SavedObjectsClientErrorCode)]: 'SavedObjectsClient/notAuthorized'
}
  log   [20:11:17.776] [info][status] Kibana is now degraded
  log   [20:11:17.779] [info][plugins][ruleRegistry] Installed common resources shared between all indices
  log   [20:11:17.780] [info][plugins][ruleRegistry] Installing resources for index .alerts-observability.uptime.alerts
  log   [20:11:17.781] [info][plugins][ruleRegistry] Installing resources for index .alerts-observability.logs.alerts
  log   [20:11:17.781] [info][plugins][ruleRegistry] Installing resources for index .alerts-observability.metrics.alerts  log   [20:11:17.782] [info][plugins][ruleRegistry] Installing resources for index .alerts-observability.apm.alerts
  log   [20:11:17.784] [info][plugins][securitySolution] Dependent plugin setup complete - Starting ManifestTask
  log   [20:11:17.786] [info][plugins][ruleRegistry] Installed resources for index .alerts-observability.apm.alerts
  log   [20:11:17.787] [info][plugins][ruleRegistry] Installed resources for index .alerts-observability.uptime.alerts
  log   [20:11:17.788] [info][plugins][ruleRegistry] Installed resources for index .alerts-observability.metrics.alerts
  log   [20:11:17.789] [info][plugins][ruleRegistry] Installed resources for index .alerts-observability.logs.alerts
  log   [20:11:20.634] [error][plugins][taskManager] Failed to poll for work: cannot execute scripts using [number_sort] context,cannot execute scripts using [number_sort] context
  log   [20:11:23.645] [error][plugins][taskManager] Failed to poll for work: cannot execute scripts using [number_sort] context,cannot execute scripts using [number_sort] context

From Kibana to Elasticsearch