packages feed

bloodhound-1.0.0.0: src/Database/Bloodhound/ElasticSearch9/Client.hs

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}

-- |
-- Module      : Database.Bloodhound.ElasticSearch9.Client
-- Description : Elasticsearch 9 client (re-exports Common + ES9-specific APIs)
--
-- The Elasticsearch 9 client. Re-exports the version-agnostic "Database.Bloodhound.Common.Client"
-- surface and adds ES9-specific features: k-NN search, point in time (PIT), ES|QL
-- and EQL (sync and async, plus ES|QL views), data streams and lifecycles, query
-- rulesets, search applications, inference endpoints, and the terms enum API.
module Database.Bloodhound.ElasticSearch9.Client
  ( module Reexport,
    knnSearch,
    pitSearch,
    pitSearchWith,
    openPointInTime,
    openPointInTimeWith,
    openPointInTimeWithBody,
    closePointInTime,
    esql,
    esqlWith,
    eqlSearch,
    eqlSearchWith,
    getEQLSearch,
    getEQLStatus,
    deleteEQLSearch,
    esqlAsync,
    esqlAsyncWith,
    getAsyncESQL,
    getAsyncESQLWith,
    deleteAsyncESQL,
    stopAsyncESQL,
    putESQLView,
    getESQLView,
    deleteESQLView,
    getESQLQuery,
    getESQLQueries,
    getDataStreams,
    getDataStreamStats,
    createDataStream,
    dataStreamExists,
    deleteDataStream,
    migrateToDataStream,
    promoteDataStream,
    putDataStreamLifecycle,
    putDataStreamsLifecycle,
    getDataStreamLifecycle,
    deleteDataStreamLifecycle,
    modifyDataStream,
    getDataStreamOptions,
    updateDataStreamOptions,
    deleteDataStreamOptions,
    getDataStreamLifecycleStats,
    explainDataStreamLifecycle,
    explainDataStreamLifecycleWith,
    getDataStreamMappings,
    getDataStreamMappingsWith,
    putDataStreamMappings,
    putDataStreamMappingsWith,
    getDataStreamSettings,
    getDataStreamSettingsWith,
    putDataStreamSettings,
    putDataStreamSettingsWith,
    putInferenceEndpoint,
    putInferenceEndpointWith,
    updateInferenceEndpoint,
    getInferenceEndpoints,
    deleteInferenceEndpoint,
    deleteInferenceEndpointWith,
    runInference,
    runInferenceWith,
    streamCompletionInference,
    streamCompletionInferenceWith,
    streamChatCompletionInference,
    streamChatCompletionInferenceWith,
    putQueryRuleset,
    getQueryRuleset,
    deleteQueryRuleset,
    testQueryRuleset,
    putSearchApplication,
    putSearchApplicationWith,
    getSearchApplication,
    deleteSearchApplication,
    searchApplication,
    searchApplicationWith,
    listSearchApplications,
    listSearchApplicationsWith,
    renderSearchApplicationQuery,
    getTermsEnum,
    getTermsEnumWith,
    resolveCluster,
    resolveClusterWith,
    getHealthReport,
    getHealthReportWith,
    getFeatures,
    getFeaturesWith,
    resetFeatures,
    resetFeaturesWith,
    putMlDataFrameAnalytics,
    putMlDataFrameAnalyticsWith,
    getMlDataFrameAnalytics,
    getMlDataFrameAnalyticsWith,
    updateMlDataFrameAnalytics,
    updateMlDataFrameAnalyticsWith,
    deleteMlDataFrameAnalytics,
    deleteMlDataFrameAnalyticsWith,
    startMlDataFrameAnalytics,
    startMlDataFrameAnalyticsWith,
    stopMlDataFrameAnalytics,
    stopMlDataFrameAnalyticsWith,
    getMlDataFrameAnalyticsStats,
    getMlDataFrameAnalyticsStatsWith,
    previewMlDataFrameAnalytics,
    MlDataFrameAnalyticsId (..),
    MlDataFrameAnalyticsPutBody (..),
    defaultMlDataFrameAnalyticsPutBody,
    MlDataFrameAnalyticsUpdateBody (..),
    defaultMlDataFrameAnalyticsUpdateBody,
    MlDataFrameAnalyticsPreviewRequest (..),
    MlDataFrameAnalyticsOptions (..),
    defaultMlDataFrameAnalyticsOptions,
    MlDataFrameAnalyticsGetResponse (..),
    MlDataFrameAnalyticsStatsResponse (..),
    MlDataFrameAnalyticsPreviewResponse (..),
    putMlTrainedModel,
    putMlTrainedModelWith,
    getMlTrainedModels,
    getMlTrainedModelsWith,
    getMlTrainedModelDefinition,
    getMlTrainedModelDefinitionWith,
    updateMlTrainedModel,
    updateMlTrainedModelWith,
    deleteMlTrainedModel,
    deleteMlTrainedModelWith,
    deployMlTrainedModel,
    deployMlTrainedModelWith,
    undeployMlTrainedModel,
    undeployMlTrainedModelWith,
    startMlTrainedModelDeployment,
    startMlTrainedModelDeploymentWith,
    stopMlTrainedModelDeployment,
    stopMlTrainedModelDeploymentWith,
    getMlTrainedModelStats,
    getMlTrainedModelStatsWith,
    inferMlTrainedModel,
    MlTrainedModelId (..),
    MlTrainedModelPutBody (..),
    defaultMlTrainedModelPutBody,
    MlTrainedModelUpdateBody (..),
    defaultMlTrainedModelUpdateBody,
    MlTrainedModelInferRequest (..),
    MlTrainedModelOptions (..),
    defaultMlTrainedModelOptions,
    MlTrainedModelsResponse (..),
    MlTrainedModelDefinition (..),
    MlTrainedModelStatsResponse (..),
    MlTrainedModelInferResponse (..),
    putMlAnomalyJob,
    getMlAnomalyJobs,
    getMlAnomalyJobsWith,
    updateMlAnomalyJob,
    deleteMlAnomalyJob,
    deleteMlAnomalyJobWith,
    openMlAnomalyJob,
    closeMlAnomalyJob,
    forecastMlAnomalyJob,
    flushMlAnomalyJob,
    validateMlAnomalyJob,
    getMlAnomalyJobStats,
    getMlAnomalyJobStatsWith,
    getMlAnomalyJobResults,
    getMlAnomalyJobResultsWith,
    getMlModelSnapshots,
    getMlModelSnapshotsWith,
    getMlModelSnapshot,
    getMlModelSnapshotWith,
    updateMlModelSnapshot,
    deleteMlModelSnapshot,
    deleteMlModelSnapshotWith,
    revertMlModelSnapshot,
    revertMlModelSnapshotWith,
    putMlDatafeed,
    getMlDatafeeds,
    getMlDatafeedsWith,
    updateMlDatafeed,
    deleteMlDatafeed,
    startMlDatafeed,
    stopMlDatafeed,
    previewMlDatafeed,
    putMlFilter,
    getMlFilters,
    getMlFiltersWith,
    deleteMlFilter,
    putMlCalendar,
    getMlCalendars,
    getMlCalendarsWith,
    deleteMlCalendar,
    setMlScheduledEvents,
    getMlScheduledEvents,
    MlJobId (..),
    MlModelSnapshotId (..),
    MlAnomalyResultType (..),
    MlAnomalyJob (..),
    defaultMlAnomalyJob,
    MlAnomalyJobUpdate (..),
    defaultMlAnomalyJobUpdate,
    MlForecastOptions (..),
    defaultMlForecastOptions,
    MlFlushOptions (..),
    defaultMlFlushOptions,
    MlAnomalyJobOptions (..),
    defaultMlAnomalyJobOptions,
    MlAnomalyJobsResponse (..),
    MlAnomalyJobStatsResponse (..),
    MlForecastResponse (..),
    MlFlushResponse (..),
    MlValidateResponse (..),
    MlAnomalyJobResults (..),
    MlModelSnapshotsResponse (..),
    MlRevertSnapshotResponse (..),
    MlDatafeedId (..),
    MlDatafeed (..),
    defaultMlDatafeed,
    MlDatafeedUpdate (..),
    defaultMlDatafeedUpdate,
    MlDatafeedOptions (..),
    defaultMlDatafeedOptions,
    MlDatafeedsResponse (..),
    MlDatafeedPreviewResponse (..),
    MlFilterId (..),
    MlFilter (..),
    defaultMlFilter,
    MlFiltersResponse (..),
    MlCalendarId (..),
    MlCalendar (..),
    defaultMlCalendar,
    MlCalendarsResponse (..),
    MlScheduledEvents (..),
    MlScheduledEventsResponse (..),
    TermValue (..),
    TermsEnumRequest (..),
    defaultTermsEnumRequest,
    TermsEnumOptions (..),
    defaultTermsEnumOptions,
    termsEnumOptionsParams,
    TermsEnumResponse (..),
    getStreamsStatus,
    getStreamsStatusWith,
    enableStream,
    enableStreamWith,
    disableStream,
    disableStreamWith,
    downsampleIndex,
    downsampleIndexWith,
    StreamName (..),
    StreamStatus (..),
    StreamsStatusResponse (..),
    streamStatusFor,
    GetStreamsStatusOptions (..),
    defaultGetStreamsStatusOptions,
    getStreamsStatusOptionsParams,
    StreamsActionOptions (..),
    defaultStreamsActionOptions,
    getGeoIpStats,
    getGeoIpDatabases,
    getGeoIpDatabase,
    putGeoIpDatabase,
    deleteGeoIpDatabase,
    getIpLocationDatabases,
    getIpLocationDatabase,
    putIpLocationDatabase,
    deleteIpLocationDatabase,
    GeoIpDatabaseId (..),
    GeoIpDatabasePutBody (..),
    IpLocationDatabasePutBody (..),
    GeoIpMaxmindConfig (..),
    GeoIpDatabasesResponse (..),
    GeoIpDatabaseInfo (..),
    GeoIpStatsResponse (..),
    GeoIpStats (..),
    simulateIngest,
    simulateIngestWith,
    simulateIngestIndex,
    simulateIngestIndexWith,
    simulateIngestGet,
    simulateIngestWithGet,
    simulateIngestIndexGet,
    simulateIngestIndexWithGet,
    SimulateIngestRequest (..),
    SimulateIngestDoc (..),
    SimulateIngestOptions (..),
    defaultSimulateIngestOptions,
    SimulateIngestResponse (..),
    SimulateIngestMergeType (..),
    migrateReindex,
    cancelMigrateReindex,
    getMigrateReindexStatus,
    createIndexFrom,
    createIndexFromWith,
    MigrateReindexMode (..),
    MigrateReindexSource (..),
    MigrateReindexRequest (..),
    mkMigrateReindexRequest,
    MigrateReindexInProgress (..),
    MigrateReindexError (..),
    MigrateReindexStatus (..),
    CreateIndexFromBody (..),
    defaultCreateIndexFromBody,
    CreateIndexFromResponse (..),
  )
where

import Control.Monad
import Data.Aeson
import Data.ByteString.Lazy qualified as L
import Data.List.NonEmpty (NonEmpty)
import Data.Text (Text)
import Database.Bloodhound.Client.Cluster
import Database.Bloodhound.Common.Client as Reexport
import Database.Bloodhound.Common.Requests as Requests
import Database.Bloodhound.ElasticSearch7.Requests qualified as Requests7
import Database.Bloodhound.ElasticSearch9.Requests qualified as Requests9
import Database.Bloodhound.ElasticSearch9.Types
import Database.Bloodhound.Internal.Utils.Requests
import Prelude hiding (filter, head)

-- | 'pitSearch' uses the point in time (PIT) API of elastic, for a given
-- 'IndexName'. Requires Elasticsearch 9. The supplied 'KeepAlive'
-- duration is forwarded to every PIT open\/extend call. Note that this will
-- consume the entire search result set and will be doing O(n) list appends so
-- this may not be suitable for large result sets. In that case, the point in
-- time API should be used directly with `openPointInTime` and `closePointInTime`.
--
-- This is a convenience wrapper around 'pitSearchWith' that lifts the
-- single 'IndexName' into an 'IndexPattern'. To search across multiple
-- comma-joined indices or a wildcard pattern, use 'pitSearchWith'
-- directly with an 'IndexPattern'.
--
-- Note that 'pitSearch' utilizes the 'search_after' parameter under the hood,
-- which requires a non-empty 'sortBody' field in the provided 'Search' value.
-- Otherwise, 'pitSearch' will fail to return all matching documents.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
pitSearch ::
  forall a m.
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  KeepAlive ->
  Search ->
  m [Hit a]
pitSearch indexName = pitSearchWith (IndexPattern (unIndexName indexName))

-- | 'pitSearchWith' is the parameterized variant of 'pitSearch': it
-- takes an 'IndexPattern' as the target, which may be a single index
-- name, a comma-separated list of indices, or a wildcard pattern
-- (e.g. @\"logs-*\"@, @\"logs-2024,logs-2025\"@). Otherwise behaves
-- exactly like 'pitSearch'. See 'openPointInTimeWith' for the target
-- rendering.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
pitSearchWith ::
  forall a m.
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexPattern ->
  KeepAlive ->
  Search ->
  m [Hit a]
pitSearchWith indexPattern keepAlive search = do
  openResp <- openPointInTimeWith indexPattern keepAlive defaultPITOptions
  case openResp of
    Left e -> throwEsError e
    Right OpenPointInTimeResponse {..} -> do
      let searchPIT = search {pointInTime = Just (PointInTime oes9PitId (Just keepAlive))}
      hits <- pitAccumulator searchPIT []
      closeResp <- closePointInTime (ClosePointInTime oes9PitId)
      case closeResp of
        Left _ -> return []
        Right (ClosePointInTimeResponse False _) ->
          error "failed to close point in time (PIT)"
        Right (ClosePointInTimeResponse True _) -> return hits
  where
    pitAccumulator :: Search -> [Hit a] -> m [Hit a]
    pitAccumulator search' oldHits = do
      resp <- tryPerformBHRequest $ Requests.searchAll search'
      case resp of
        Left _ -> return []
        Right searchResult -> case hits (searchHits searchResult) of
          [] -> return oldHits
          newHits -> case (hitSort $ last newHits, pitId searchResult) of
            (Nothing, Nothing) ->
              error "no point in time (PIT) ID or last sort value"
            (Just _, Nothing) -> error "no point in time (PIT) ID"
            (Nothing, _) -> return (oldHits <> newHits)
            (Just lastSort, Just pitId') -> do
              let newSearch =
                    search'
                      { pointInTime = Just (PointInTime pitId' (Just keepAlive)),
                        searchAfterKey = Just lastSort
                      }
              pitAccumulator newSearch (oldHits <> newHits)

-- | 'openPointInTime' opens a point in time for an index given an 'IndexName'
-- and a 'KeepAlive' duration (e.g. @keepAliveMinutes 1@). Note that the point
-- in time should be closed with 'closePointInTime' as soon as it is no longer
-- needed.
--
-- Equivalent to 'openPointInTimeWith' with
-- 'Database.Bloodhound.Internal.Versions.Common.Types.PointInTime.defaultPITOptions'
-- (no optional URI parameters).
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
openPointInTime ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  KeepAlive ->
  m (ParsedEsResponse OpenPointInTimeResponse)
openPointInTime indexName keepAlive = performBHRequest $ Requests9.openPointInTime indexName keepAlive

-- | 'openPointInTimeWith' is the parameterized variant of
-- 'openPointInTime': it takes an 'IndexPattern' target (single name,
-- comma-list, or wildcard) and forwards the supplied 'PITOptions' as
-- query-string parameters in addition to the mandatory @keep_alive@.
-- Delegates to the ES9 request builder (which is local to ES9, not
-- shared with ES7). See
-- 'Database.Bloodhound.ElasticSearch9.Requests.openPointInTimeWith'
-- for which parameters are emitted.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
openPointInTimeWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexPattern ->
  KeepAlive ->
  PITOptions ->
  m (ParsedEsResponse OpenPointInTimeResponse)
openPointInTimeWith indexPattern keepAlive opts =
  performBHRequest $ Requests9.openPointInTimeWith indexPattern keepAlive opts

-- | 'openPointInTimeWithBody' is the body-carrying variant of
-- 'openPointInTimeWith': it sends the supplied 'OpenPointInTimeBody' as
-- the JSON request body (the only way to supply an @index_filter@
-- query), in addition to the 'PITOptions' URI parameters and the
-- mandatory @keep_alive@. The 'IndexPattern' target follows the same
-- rules as 'openPointInTimeWith'. Delegates to the ES9 request builder.
-- See
-- 'Database.Bloodhound.ElasticSearch9.Requests.openPointInTimeWithBody'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
openPointInTimeWithBody ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexPattern ->
  KeepAlive ->
  OpenPointInTimeBody ->
  PITOptions ->
  m (ParsedEsResponse OpenPointInTimeResponse)
openPointInTimeWithBody indexPattern keepAlive body opts =
  performBHRequest $ Requests9.openPointInTimeWithBody indexPattern keepAlive body opts

-- | 'closePointInTime' closes a point in time given a 'ClosePointInTime'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/point-in-time-api.html>.
closePointInTime ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ClosePointInTime ->
  m (ParsedEsResponse ClosePointInTimeResponse)
closePointInTime q = performBHRequest $ Requests9.closePointInTime q

-- | 'esql' executes an ES|QL query synchronously via @POST /_query@
-- (Elasticsearch 9.x). The result is returned as an 'ESQLResult' containing
-- column descriptors and row values.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-rest.html>.
esql ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ESQLRequest ->
  m (ParsedEsResponse ESQLResult)
esql = performBHRequest . Requests9.esql

-- | 'esqlWith' executes an ES|QL query synchronously via @POST /_query@
-- (Elasticsearch 9.x) with the documented URI query parameters
-- ('ESQLQueryOptions'). Pass 'defaultESQLQueryOptions' to behave
-- identically to 'esql'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-rest.html>.
esqlWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ESQLRequest ->
  ESQLQueryOptions ->
  m (ParsedEsResponse ESQLResult)
esqlWith req = performBHRequest . Requests9.esqlWith req

-- | 'eqlSearch' submits an EQL (Event Query Language) search via
-- @POST /{index}/_eql/search@ (Elasticsearch 9.x). The result is
-- parameterized by the document-source type @a@.
--
-- The wire format is identical to ES 7.10+\/8.x, so the ES9 request
-- builder delegates to the ES8 implementation.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html>.
eqlSearch ::
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  EQLRequest ->
  m (ParsedEsResponse (EQLResult a))
eqlSearch indexName req = performBHRequest $ Requests9.eqlSearch indexName req

-- | 'eqlSearchWith' is the fully-parameterised form of 'eqlSearch'. The
-- wire format is identical to ES 7.10+\/8.x, so the ES9 request builder
-- delegates to the ES8 implementation. See 'EQLSearchOptions' for the
-- available URI parameters.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/eql-search-api.html>.
eqlSearchWith ::
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  EQLSearchOptions ->
  EQLRequest ->
  m (ParsedEsResponse (EQLResult a))
eqlSearchWith indexName opts req =
  performBHRequest $ Requests9.eqlSearchWith indexName opts req

-- | 'getEQLSearch' fetches the deferred results of an async EQL search
-- via @GET /_eql/search\/{id}@ (Elasticsearch 9.x). The result is
-- parameterized by the document-source type @a@. The optional 'Text'
-- sets @wait_for_completion_timeout@ as a query parameter; 'Nothing'
-- returns immediately with the current state.
--
-- The wire format is identical to ES 7.10+\/8.x, so the ES9 request
-- builder delegates to the ES8 implementation.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-eql-get>.
getEQLSearch ::
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  EQLSearchId ->
  Maybe Text ->
  m (ParsedEsResponse (EQLResult a))
getEQLSearch sid = performBHRequest . Requests9.getEQLSearch sid

-- | 'getEQLStatus' returns only the status of an async EQL search via
-- @GET /_eql/search/status\/{id}@ (Elasticsearch 9.x) without fetching
-- the results.
--
-- The wire format is identical to ES 7.10+\/8.x, so the ES9 request
-- builder delegates to the ES8 implementation (which delegates to ES7).
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-eql-get-status>.
getEQLStatus ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  EQLSearchId ->
  m EQLStatus
getEQLStatus = performBHRequest . Requests9.getEQLStatus

-- | 'esqlAsync' submits a long-running ES|QL query via @POST /_query/async@
-- on Elasticsearch 9. The wire format is identical to ES8. See
-- "Database.Bloodhound.ElasticSearch8.Client"#esqlAsync for details.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-async.html>.
esqlAsync ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLRequest ->
  m (ParsedEsResponse AsyncESQLResult)
esqlAsync = performBHRequest . Requests9.esqlAsync

-- | 'esqlAsyncWith' submits a long-running ES|QL query via
-- @POST /_query/async@ on Elasticsearch 9 with the documented URI query
-- parameters. The wire format is identical to ES8. See
-- "Database.Bloodhound.ElasticSearch8.Client"#esqlAsyncWith for details.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-async.html>.
esqlAsyncWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLRequest ->
  ESQLQueryOptions ->
  m (ParsedEsResponse AsyncESQLResult)
esqlAsyncWith req = performBHRequest . Requests9.esqlAsyncWith req

-- | 'getAsyncESQL' polls an async ES|QL query by id on Elasticsearch 9.
-- The wire format is identical to ES8. See
-- "Database.Bloodhound.ElasticSearch8.Client"#getAsyncESQL for details.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-async.html>.
getAsyncESQL ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLId ->
  Maybe Text ->
  m (ParsedEsResponse AsyncESQLResult)
getAsyncESQL = (performBHRequest .) . Requests9.getAsyncESQL

-- | 'getAsyncESQLWith' is the fully-parameterised form of 'getAsyncESQL'
-- on Elasticsearch 9. The wire format is identical to ES8. See
-- "Database.Bloodhound.ElasticSearch8.Client"#getAsyncESQLWith for details.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-async.html>.
getAsyncESQLWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLId ->
  GetAsyncESQLOptions ->
  m (ParsedEsResponse AsyncESQLResult)
getAsyncESQLWith = (performBHRequest .) . Requests9.getAsyncESQLWith

-- | 'deleteAsyncESQL' deletes an async ES|QL result and its context by id
-- on Elasticsearch 9. The wire format is identical to ES8. Deleting a
-- non-existent or already-purged async id surfaces as an 'EsError' (a
-- @404@ with an error body); wrap with 'tryEsError' for miss-tolerant
-- deletion.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-async.html>.
deleteAsyncESQL ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLId ->
  m Acknowledged
deleteAsyncESQL = performBHRequest . Requests9.deleteAsyncESQL

-- | 'stopAsyncESQL' requests the server to stop a running async ES|QL
-- query by id on Elasticsearch 9. Maps to @POST /_query/async/{id}/stop@
-- (Elasticsearch 8.11+) and returns the final 'AsyncESQLResult' —
-- @is_running@ will be @False@ and @columns@\/@values@ carry whatever
-- the query produced before being stopped. The wire format is identical
-- to ES8.
--
-- For more information see
-- <https://www.elastic.co/docs/reference/elasticsearch/rest-apis/esql-async-api>.
stopAsyncESQL ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLId ->
  m (ParsedEsResponse AsyncESQLResult)
stopAsyncESQL = performBHRequest . Requests9.stopAsyncESQL

-- | 'putInferenceEndpoint' creates or updates an inference endpoint via
-- @PUT \/_inference\/{task_type}\/{inference_id}@ on Elasticsearch 9. The
-- wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html>.
putInferenceEndpoint ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  InferenceConfig ->
  m (ParsedEsResponse InferencePutResponse)
putInferenceEndpoint taskType' inferenceId config =
  performBHRequest $ Requests9.putInferenceEndpoint taskType' inferenceId config

-- | Fully-parameterised form of 'putInferenceEndpoint'. The wire format is
-- identical to ES8. Pass 'PutInferenceOptions' to attach the @timeout@ query
-- parameter; see 'Requests9.putInferenceEndpointWith'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html>.
putInferenceEndpointWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  InferenceConfig ->
  PutInferenceOptions ->
  m (ParsedEsResponse InferencePutResponse)
putInferenceEndpointWith taskType' inferenceId config opts =
  performBHRequest $ Requests9.putInferenceEndpointWith taskType' inferenceId config opts

-- | 'updateInferenceEndpoint' partially updates an existing inference
-- endpoint via @PUT \/_inference\/{task_type}\/{inference_id}\/_update@ on
-- Elasticsearch 9. The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-update>.
updateInferenceEndpoint ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  InferenceConfig ->
  m (ParsedEsResponse InferenceInfo)
updateInferenceEndpoint taskType' inferenceId config =
  performBHRequest $ Requests9.updateInferenceEndpoint taskType' inferenceId config

-- | 'getInferenceEndpoints' lists configured inference endpoints via the
-- @GET \/_inference@ family on Elasticsearch 9. The wire format is
-- identical to ES8. See "Database.Bloodhound.ElasticSearch8.Client" for
-- the filter semantics.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/get-inference-api.html>.
getInferenceEndpoints ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe TaskType ->
  Maybe InferenceId ->
  m [InferenceInfo]
getInferenceEndpoints mTaskType mInferenceId =
  performBHRequest $ Requests9.getInferenceEndpoints mTaskType mInferenceId

-- | 'deleteInferenceEndpoint' deletes an inference endpoint via
-- @DELETE \/_inference\/{task_type}\/{inference_id}@ on Elasticsearch 9. The
-- wire format is identical to ES8. Deleting a non-existent endpoint surfaces
-- as an 'EsError'; wrap with 'tryPerformBHRequest' for miss-tolerant deletion.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-inference-api.html>.
deleteInferenceEndpoint ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  m Acknowledged
deleteInferenceEndpoint taskType' inferenceId =
  performBHRequest $ Requests9.deleteInferenceEndpoint taskType' inferenceId

-- | Fully-parameterised form of 'deleteInferenceEndpoint'. Pass
-- 'DeleteInferenceOptions' to attach the @dry_run@ and @force@ query
-- parameters. The wire format is identical to ES8; see
-- 'Requests9.deleteInferenceEndpointWith'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-inference-api.html>.
deleteInferenceEndpointWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  DeleteInferenceOptions ->
  m Acknowledged
deleteInferenceEndpointWith taskType' inferenceId opts =
  performBHRequest $ Requests9.deleteInferenceEndpointWith taskType' inferenceId opts

-- | 'runInference' performs inference against an existing endpoint via
-- @POST \/_inference\/{task_type}\/{inference_id}@ on Elasticsearch 9. The
-- wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html>.
runInference ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  InferenceInput ->
  m (ParsedEsResponse InferenceResult)
runInference taskType' inferenceId input =
  performBHRequest $ Requests9.runInference taskType' inferenceId input

-- | Fully-parameterised form of 'runInference'. The wire format is identical
-- to ES8. Pass 'RunInferenceOptions' to attach the @timeout@ query parameter;
-- see 'Requests9.runInferenceWith'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/inference-apis.html>.
runInferenceWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  TaskType ->
  InferenceId ->
  InferenceInput ->
  RunInferenceOptions ->
  m (ParsedEsResponse InferenceResult)
runInferenceWith taskType' inferenceId input opts =
  performBHRequest $ Requests9.runInferenceWith taskType' inferenceId input opts

-- | 'streamCompletionInference' streams completion chunks from an existing
-- completion endpoint via
-- @POST \/_inference\/completion\/{inference_id}\/_stream@ on Elasticsearch 9.
-- The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-stream-completion>.
streamCompletionInference ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  InferenceId ->
  InferenceInput ->
  m L.ByteString
streamCompletionInference inferenceId input =
  performBHRequest $ Requests9.streamCompletionInference inferenceId input

-- | Fully-parameterised form of 'streamCompletionInference'. The wire format
-- is identical to ES8. Pass 'StreamCompletionInferenceOptions' to attach the
-- @timeout@ query parameter; see 'Requests9.streamCompletionInferenceWith'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-stream-completion>.
streamCompletionInferenceWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  InferenceId ->
  InferenceInput ->
  StreamCompletionInferenceOptions ->
  m L.ByteString
streamCompletionInferenceWith inferenceId input opts =
  performBHRequest $ Requests9.streamCompletionInferenceWith inferenceId input opts

-- | 'streamChatCompletionInference' streams chat-completion chunks from an
-- existing chat endpoint via
-- @POST \/_inference\/chat_completion\/{inference_id}\/_stream@ on
-- Elasticsearch 9. The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-chat-completion-unified>.
streamChatCompletionInference ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  InferenceId ->
  ChatCompletionRequest ->
  m L.ByteString
streamChatCompletionInference inferenceId request =
  performBHRequest $ Requests9.streamChatCompletionInference inferenceId request

-- | Fully-parameterised form of 'streamChatCompletionInference'. The wire
-- format is identical to ES8. Pass 'StreamChatCompletionInferenceOptions' to
-- attach the @timeout@ query parameter; see
-- 'Requests9.streamChatCompletionInferenceWith'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-inference-chat-completion-unified>.
streamChatCompletionInferenceWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  InferenceId ->
  ChatCompletionRequest ->
  StreamChatCompletionInferenceOptions ->
  m L.ByteString
streamChatCompletionInferenceWith inferenceId request opts =
  performBHRequest $ Requests9.streamChatCompletionInferenceWith inferenceId request opts

-- | 'putQueryRuleset' creates or updates a query ruleset via
-- @PUT \/_query_rules\/{ruleset_id}@ on Elasticsearch 9. The wire
-- format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/put-query-ruleset.html>.
putQueryRuleset ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  RulesetId ->
  QueryRuleset ->
  m QueryRulesetPutResponse
putQueryRuleset rulesetId ruleset =
  performBHRequest $ Requests9.putQueryRuleset rulesetId ruleset

-- | 'getQueryRuleset' fetches a query ruleset by id via
-- @GET \/_query_rules\/{ruleset_id}@ on Elasticsearch 9. The wire
-- format is identical to ES8. A @404@ surfaces as an 'EsError'; wrap
-- with 'tryPerformBHRequest' for miss-tolerant reads.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/get-query-ruleset.html>.
getQueryRuleset ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  RulesetId ->
  m QueryRulesetInfo
getQueryRuleset = performBHRequest . Requests9.getQueryRuleset

-- | 'deleteQueryRuleset' deletes a query ruleset by id via
-- @DELETE \/_query_rules\/{ruleset_id}@ on Elasticsearch 9. The wire
-- format is identical to ES8. Deleting a non-existent ruleset surfaces
-- as an 'EsError'; wrap with 'tryPerformBHRequest' for miss-tolerant
-- deletion.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/delete-query-ruleset.html>.
deleteQueryRuleset ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  RulesetId ->
  m Acknowledged
deleteQueryRuleset = performBHRequest . Requests9.deleteQueryRuleset

-- | 'testQueryRuleset' evaluates match criteria against a stored
-- ruleset via @POST \/_query_rules\/{ruleset_id}\/_test@ on
-- Elasticsearch 9. The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/test-query-ruleset.html>.
testQueryRuleset ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  RulesetId ->
  QueryRulesetTest ->
  m QueryRulesetTestResponse
testQueryRuleset rulesetId body =
  performBHRequest $ Requests9.testQueryRuleset rulesetId body

-- | 'putSearchApplication' creates or updates a search application via
-- @PUT \/_application\/search_application\/{name}@ on Elasticsearch 9.
-- The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-apis.html>.
putSearchApplication ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  SearchApplication ->
  m SearchApplicationPutResponse
putSearchApplication appName app =
  performBHRequest $ Requests9.putSearchApplication appName app

-- | 'putSearchApplicationWith' is the fully-parameterised form of
-- 'putSearchApplication' on Elasticsearch 9. The wire format is
-- identical to ES8. 'SearchApplicationPutOptions' carries the @create@
-- query parameter: @'Just' 'True'@ emits @?create=true@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-search-application-put>.
putSearchApplicationWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  SearchApplicationPutOptions ->
  SearchApplication ->
  m SearchApplicationPutResponse
putSearchApplicationWith appName opts app =
  performBHRequest $ Requests9.putSearchApplicationWith appName opts app

-- | 'getSearchApplication' fetches a search application by name via
-- @GET \/_application\/search_application\/{name}@ on Elasticsearch 9.
-- The wire format is identical to ES8. A @404@ surfaces as an
-- 'EsError'; wrap with 'tryPerformBHRequest' for miss-tolerant reads.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-apis.html>.
getSearchApplication ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  m SearchApplicationInfo
getSearchApplication = performBHRequest . Requests9.getSearchApplication

-- | 'deleteSearchApplication' deletes a search application by name via
-- @DELETE \/_application\/search_application\/{name}@ on Elasticsearch 9.
-- The wire format is identical to ES8. Deleting a non-existent
-- application surfaces as an 'EsError'; wrap with
-- 'tryPerformBHRequest' for miss-tolerant deletion.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-apis.html>.
deleteSearchApplication ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  m Acknowledged
deleteSearchApplication = performBHRequest . Requests9.deleteSearchApplication

-- | 'searchApplication' runs a search application's stored template
-- against its indices via
-- @POST \/_application\/search_application\/{name}\/_search@ on
-- Elasticsearch 9. The wire format is identical to ES8.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-apis.html>.
searchApplication ::
  (FromJSON a, MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  Maybe SearchApplicationSearchParams ->
  m (ParsedEsResponse (SearchResult a))
searchApplication appName mParams =
  performBHRequest $ Requests9.searchApplication appName mParams

-- | Fully-parameterised form of 'searchApplication'. The wire format is
-- identical to ES8. Pass 'SearchApplicationOptions' to attach the @typed_keys@
-- query parameter; see 'Requests9.searchApplicationWith'.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-application-apis.html>.
searchApplicationWith ::
  (MonadBH m, WithBackend ElasticSearch9 m, FromJSON a) =>
  SearchApplicationName ->
  Maybe SearchApplicationSearchParams ->
  SearchApplicationOptions ->
  m (ParsedEsResponse (SearchResult a))
searchApplicationWith appName mParams opts =
  performBHRequest $ Requests9.searchApplicationWith appName mParams opts

-- | 'listSearchApplications' lists configured search applications via
-- @GET \/_application\/search_application@ on Elasticsearch 9. The wire
-- format is identical to ES8. Use 'listSearchApplicationsWith' to attach
-- the @q@\/@from@\/@size@ query parameters.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-search-application-list>.
listSearchApplications ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m SearchApplicationListResponse
listSearchApplications =
  performBHRequest Requests9.listSearchApplications

-- | Fully-parameterised form of 'listSearchApplications'. Pass
-- 'SearchApplicationListOptions' to attach the @q@\/@from@\/@size@ query
-- parameters; see 'Requests9.listSearchApplicationsWith'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-search-application-list>.
listSearchApplicationsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationListOptions ->
  m SearchApplicationListResponse
listSearchApplicationsWith opts =
  performBHRequest $ Requests9.listSearchApplicationsWith opts

-- | 'renderSearchApplicationQuery' renders a search application's stored
-- template against the supplied parameters and returns the resulting
-- Elasticsearch query body /without/ executing the search, via
-- @POST \/_application\/search_application\/{name}\/_render_query@ on
-- Elasticsearch 9. The wire format is identical to ES8. The response is
-- the rendered search-request body as an opaque 'Value'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-search-application-render-query>.
renderSearchApplicationQuery ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SearchApplicationName ->
  Maybe SearchApplicationSearchParams ->
  m Value
renderSearchApplicationQuery appName mParams =
  performBHRequest $ Requests9.renderSearchApplicationQuery appName mParams

-- | knnSearch executes a k-NN vector search request for Elasticsearch 9.
--
-- ES9 (like ES8) has no standalone @\/{index}\/_knn_search@ endpoint: kNN
-- is a top-level @\"knn\"@ clause in a standard @POST \/{index}\/_search@
-- body. This function injects the supplied 'KnnQuery' as a single-element
-- @\"knn\"@ array on the body of the given 'Search' and POSTs it to
-- @\/{index}\/_search@.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/knn-search.html>.
knnSearch ::
  (FromJSON a) =>
  IndexName ->
  KnnQuery ->
  Search ->
  BHRequest StatusDependant (SearchResult a)
knnSearch indexName knnQuery search =
  post @StatusDependant endpoint (encode searchWithKnn)
  where
    endpoint = mkEndpoint [unIndexName indexName, "_search"]
    searchWithKnn = search {knnBody = Just [knnQuery]}

-- | 'getDataStreams' lists data streams. The wire format is identical
-- across ES 7.x, 8.x and 9.x, so the ES7 request builder is reused
-- verbatim.
--
-- * @'Nothing'@ or @'Just' []@  → @GET /_data_stream@ returns every data
--   stream on the cluster.
-- * @'Just' names@              → @GET /_data_stream\/{a,b,c}@ returns
--   only the named data streams.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#get-data-streams>.
getDataStreams ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m [DataStreamInfo]
getDataStreams = performBHRequest . Requests7.getDataStreams

-- | 'getDataStreamStats' returns statistics about data streams
-- (document counts, store sizes, shard counts, etc.). The wire format
-- is identical to ES7, so the ES7 request builder is reused verbatim.
--
-- * @'Nothing'@ or @'Just' []@  → @GET /_data_stream/_stats@ returns
--   statistics for every data stream on the cluster.
-- * @'Just' names@              → @GET /_data_stream\/{a,b,c}/_stats@
--   returns statistics for only the named data streams.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#get-data-stream-stats>.
getDataStreamStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m DataStreamStats
getDataStreamStats = performBHRequest . Requests7.getDataStreamStats

-- | 'createDataStream' creates a data stream with the given name. The
-- stream's configuration is derived from the matching index template
-- (which must already exist and declare a @data_stream@ object). The
-- wire format is identical to ES7, so the ES7 request builder is reused
-- verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#create-data-stream>.
createDataStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  m Acknowledged
createDataStream = performBHRequest . Requests7.createDataStream

-- | 'dataStreamExists' checks whether a data stream with the given
-- name exists. Returns 'True' if the stream exists, 'False'
-- otherwise (any non-2xx status, including @404@, decodes to
-- 'False'; no 'EsError' is raised). The wire format is identical to
-- ES7, so the ES7 request builder is reused verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html>.
dataStreamExists ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  m Bool
dataStreamExists = performBHRequest . Requests7.dataStreamExists

-- | 'deleteDataStream' deletes a data stream and its backing indices.
-- Deleting a non-existent stream surfaces as an 'EsError'. The wire
-- format is identical to ES7, so the ES7 request builder is reused
-- verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#delete-data-stream>.
deleteDataStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  m Acknowledged
deleteDataStream = performBHRequest . Requests7.deleteDataStream

-- | 'migrateToDataStream' converts an existing alias (whose write index
-- is a hidden or data-stream-compatible backing index) into a data
-- stream. The alias and its write index must already be set up
-- correctly; an ineligible alias surfaces as an 'EsError'. The wire
-- format is identical to ES7, so the ES7 request builder is reused
-- verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#migrate-to-data-stream>.
migrateToDataStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexAliasName ->
  m Acknowledged
migrateToDataStream = performBHRequest . Requests7.migrateToDataStream

-- | 'promoteDataStream' promotes a frozen or cloned data stream back to a
-- regular data stream (disaster recovery). A stream that is not
-- currently frozen surfaces as an 'EsError'. The wire format is
-- identical to ES7, so the ES7 request builder is reused verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#promote-data-stream>.
promoteDataStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  m Acknowledged
promoteDataStream = performBHRequest . Requests7.promoteDataStream

-- | 'putDataStreamLifecycle' sets or updates the lifecycle of a data
-- stream (retention, downsampling, enabled toggle). The wire format
-- is identical to ES8, so the ES9 request builder delegates to ES8.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle.html#put-data-stream-lifecycle>.
putDataStreamLifecycle ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  DataStreamLifecycle ->
  m Acknowledged
putDataStreamLifecycle = (performBHRequest .) . Requests9.putDataStreamLifecycle

-- | 'putDataStreamsLifecycle' sets or updates the lifecycle of
-- multiple data streams in a single bulk request (see
-- 'PutDataStreamsLifecycleRequest'). The wire format is identical to
-- ES8, so the ES9 request builder delegates to ES8.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle.html#put-data-streams-lifecycle>.
putDataStreamsLifecycle ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  PutDataStreamsLifecycleRequest ->
  m Acknowledged
putDataStreamsLifecycle = performBHRequest . Requests9.putDataStreamsLifecycle

-- | 'getDataStreamLifecycle' retrieves the lifecycle configuration of
-- one or more data streams. The wire format is identical to ES8, so
-- the ES9 request builder delegates to ES8.
--
-- * @'Nothing'@ or @'Just' []@  → @GET /_data_stream/_lifecycle@
--   returns the lifecycle of every data stream on the cluster.
-- * @'Just' names@              → @GET /_data_stream\/{a,b,c}/_lifecycle@
--   returns only the lifecycles of the named data streams.
--
-- Streams that are not managed by a lifecycle appear with their
-- @lifecycle@ field decoded as 'Nothing'.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle.html#get-data-stream-lifecycle>.
getDataStreamLifecycle ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m GetDataStreamLifecyclesResponse
getDataStreamLifecycle = performBHRequest . Requests9.getDataStreamLifecycle

-- | 'deleteDataStreamLifecycle' removes the lifecycle configuration
-- from a data stream, rendering it unmanaged by the data stream
-- lifecycle. The wire format is identical to ES8, so the ES9 request
-- builder delegates to ES8.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-lifecycle.html#delete-data-stream-lifecycle>.
deleteDataStreamLifecycle ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  DataStreamName ->
  m Acknowledged
deleteDataStreamLifecycle = performBHRequest . Requests9.deleteDataStreamLifecycle

-- | 'modifyDataStream' changes the backing indices of one or more data
-- streams (batched add\/remove backing index). Referencing a
-- non-existent stream or an ineligible index surfaces as an 'EsError'.
-- The wire format is identical to ES7, so the ES7 request builder is
-- reused verbatim.
--
-- See
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/data-stream-apis.html#modify-data-stream>.
modifyDataStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ModifyDataStreamRequest ->
  m Acknowledged
modifyDataStream = performBHRequest . Requests7.modifyDataStream

-- | 'getDataStreamOptions' retrieves the options (e.g. failure store
-- configuration) of one or more data streams. Requires Elasticsearch
-- >= 8.19. The wire format is identical to ES8, so the ES9 request
-- builder delegates to ES8.
--
-- * @'Nothing'@ or @'Just' []@  → @GET /_data_stream/_options@
--   returns the options of every data stream on the cluster.
-- * @'Just' names@              → @GET /_data_stream\/{a,b,c}/_options@
--   returns only the options of the named data streams.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream-options>.
getDataStreamOptions ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m GetDataStreamOptionsResponse
getDataStreamOptions = performBHRequest . Requests9.getDataStreamOptions

-- | 'updateDataStreamOptions' sets the options (e.g. failure store
-- configuration) of one or more data streams. Referencing a
-- non-existent stream surfaces as an 'EsError'. Requires Elasticsearch
-- >= 8.19. The wire format is identical to ES8, so the ES9 request
-- builder delegates to ES8.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-stream-options>.
updateDataStreamOptions ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  UpdateDataStreamOptionsRequest ->
  m Acknowledged
updateDataStreamOptions = (performBHRequest .) . Requests9.updateDataStreamOptions

-- | 'deleteDataStreamOptions' removes the options (e.g. failure store
-- configuration) from one or more data streams, resetting them to
-- their defaults. Deleting the options of a non-existent stream
-- surfaces as an 'EsError'. Requires Elasticsearch >= 8.19. The wire
-- format is identical to ES8, so the ES9 request builder delegates
-- to ES8.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-delete-data-stream-options>.
deleteDataStreamOptions ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m Acknowledged
deleteDataStreamOptions = performBHRequest . Requests9.deleteDataStreamOptions

-- | 'getDataStreamLifecycleStats' retrieves cluster-wide runtime
-- statistics for the data stream lifecycle service via
-- @GET /_lifecycle/stats@ (Elasticsearch 8.12+, also in ES 9).
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-lifecycle-stats>.
getDataStreamLifecycleStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m DataStreamLifecycleStats
getDataStreamLifecycleStats = performBHRequest Requests9.getDataStreamLifecycleStats

-- | 'explainDataStreamLifecycle' retrieves the per-index lifecycle
-- status for one or more backing indices via
-- @GET /{index}/_lifecycle/explain@ (Elasticsearch 8.11+, also in ES 9).
-- Equivalent to
-- @'explainDataStreamLifecycleWith' indices 'defaultExplainDataStreamLifecycleOptions'@.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-explain-data-lifecycle>.
explainDataStreamLifecycle ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [IndexName] ->
  m ExplainDataStreamLifecycleResponse
explainDataStreamLifecycle = performBHRequest . Requests9.explainDataStreamLifecycle

-- | 'explainDataStreamLifecycleWith' is the fully-parameterised form
-- of 'explainDataStreamLifecycle'.
explainDataStreamLifecycleWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [IndexName] ->
  ExplainDataStreamLifecycleOptions ->
  m ExplainDataStreamLifecycleResponse
explainDataStreamLifecycleWith indices =
  performBHRequest . Requests9.explainDataStreamLifecycleWith indices

-- | 'getDataStreamMappings' retrieves the mapping configuration of
-- one or more data streams via @GET /_data_stream\/{name}/_mappings@
-- (Elasticsearch 9.1+). Equivalent to
-- @'getDataStreamMappingsWith' names 'defaultGetDataStreamMappingsOptions'@.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream-mappings>.
getDataStreamMappings ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m GetDataStreamMappingsResponse
getDataStreamMappings = performBHRequest . Requests9.getDataStreamMappings

-- | 'getDataStreamMappingsWith' is the fully-parameterised form of
-- 'getDataStreamMappings'.
getDataStreamMappingsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  GetDataStreamMappingsOptions ->
  m GetDataStreamMappingsResponse
getDataStreamMappingsWith names =
  performBHRequest . Requests9.getDataStreamMappingsWith names

-- | 'putDataStreamMappings' updates the mapping configuration of one
-- or more data streams via @PUT /_data_stream\/{name}/_mappings@
-- (Elasticsearch 9.2+). Equivalent to
-- @'putDataStreamMappingsWith' names mapping 'defaultUpdateDataStreamMappingsOptions'@.
-- The body is any 'ToJSON'able mapping object.
--
-- /CAUTION/: when given @'Nothing'@ or @'Just' []@, the wildcard @*@
-- is substituted for the @{name}@ segment, applying the override to
-- every data stream on the cluster.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-stream-mappings>.
putDataStreamMappings ::
  (MonadBH m, WithBackend ElasticSearch9 m, ToJSON mapping) =>
  Maybe [DataStreamName] ->
  mapping ->
  m UpdateDataStreamMappingsResponse
putDataStreamMappings names = performBHRequest . Requests9.putDataStreamMappings names

-- | 'putDataStreamMappingsWith' is the fully-parameterised form of
-- 'putDataStreamMappings'.
putDataStreamMappingsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m, ToJSON mapping) =>
  Maybe [DataStreamName] ->
  mapping ->
  UpdateDataStreamMappingsOptions ->
  m UpdateDataStreamMappingsResponse
putDataStreamMappingsWith names mapping =
  performBHRequest . Requests9.putDataStreamMappingsWith names mapping

-- | 'getDataStreamSettings' retrieves the settings configuration of
-- one or more data streams via @GET /_data_stream\/{name}/_settings@
-- (Elasticsearch 9.1+). Equivalent to
-- @'getDataStreamSettingsWith' names 'defaultGetDataStreamSettingsOptions'@.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-get-data-stream-settings>.
getDataStreamSettings ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  m GetDataStreamSettingsResponse
getDataStreamSettings = performBHRequest . Requests9.getDataStreamSettings

-- | 'getDataStreamSettingsWith' is the fully-parameterised form of
-- 'getDataStreamSettings'.
getDataStreamSettingsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [DataStreamName] ->
  GetDataStreamSettingsOptions ->
  m GetDataStreamSettingsResponse
getDataStreamSettingsWith names =
  performBHRequest . Requests9.getDataStreamSettingsWith names

-- | 'putDataStreamSettings' updates the settings configuration of one
-- or more data streams via @PUT /_data_stream\/{name}/_settings@
-- (Elasticsearch 9.1+, also documented as available in 8.19).
-- Equivalent to
-- @'putDataStreamSettingsWith' names settings 'defaultUpdateDataStreamSettingsOptions'@.
-- The body is any 'ToJSON'able settings object.
--
-- /CAUTION/: when given @'Nothing'@ or @'Just' []@, the wildcard @*@
-- is substituted for the @{name}@ segment, applying the override to
-- every data stream on the cluster.
--
-- See
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-put-data-stream-settings>.
putDataStreamSettings ::
  (MonadBH m, WithBackend ElasticSearch9 m, ToJSON settings) =>
  Maybe [DataStreamName] ->
  settings ->
  m UpdateDataStreamSettingsResponse
putDataStreamSettings names = performBHRequest . Requests9.putDataStreamSettings names

-- | 'putDataStreamSettingsWith' is the fully-parameterised form of
-- 'putDataStreamSettings'.
putDataStreamSettingsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m, ToJSON settings) =>
  Maybe [DataStreamName] ->
  settings ->
  UpdateDataStreamSettingsOptions ->
  m UpdateDataStreamSettingsResponse
putDataStreamSettingsWith names settings =
  performBHRequest . Requests9.putDataStreamSettingsWith names settings

-- | 'deleteEQLSearch' deletes an async EQL search result and its
-- context by id via @DELETE /_eql/search/{id}@ (Elasticsearch 7.10+)
-- and returns 'Acknowledged' on success.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-eql-delete>.
deleteEQLSearch ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  EQLSearchId ->
  m Acknowledged
deleteEQLSearch = performBHRequest . Requests9.deleteEQLSearch

-- | 'putESQLView' creates or updates an ES|QL view via
-- @PUT \/_query\/view\/{name}@ on Elasticsearch 9 (9.4+,
-- experimental). This endpoint does not exist on Elasticsearch 8.x, so
-- the canonical request builder lives only in the ES9 module (see
-- "Database.Bloodhound.ElasticSearch9.Requests").
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-put-view>.
putESQLView ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ESQLViewName ->
  Text ->
  m Acknowledged
putESQLView viewName query =
  performBHRequest $ Requests9.putESQLView viewName query

-- | 'getESQLView' fetches an ES|QL view by name via
-- @GET \/_query\/view\/{name}@ on Elasticsearch 9 (9.4+,
-- experimental). This endpoint does not exist on Elasticsearch 8.x, so
-- the canonical request builder lives only in the ES9 module.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-view>.
getESQLView ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ESQLViewName ->
  m ESQLView
getESQLView = performBHRequest . Requests9.getESQLView

-- | 'deleteESQLView' deletes an ES|QL view by name via
-- @DELETE \/_query\/view\/{name}@ on Elasticsearch 9 (9.4+,
-- experimental). This endpoint does not exist on Elasticsearch 8.x, so
-- the canonical request builder lives only in the ES9 module.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-delete-view>.
deleteESQLView ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ESQLViewName ->
  m Acknowledged
deleteESQLView = performBHRequest . Requests9.deleteESQLView

-- | 'getESQLQuery' fetches information about a currently-running ES|QL
-- query via @GET \/_query\/queries\/{id}@ on Elasticsearch 9 (9.1+,
-- experimental). This endpoint does not exist on Elasticsearch 8.x, so
-- the canonical request builder lives only in the ES9 module.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-get-query>.
getESQLQuery ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  AsyncESQLId ->
  m ESQLQueryInfo
getESQLQuery = performBHRequest . Requests9.getESQLQuery

-- | 'getESQLQueries' lists every currently-running ES|QL query via
-- @GET \/_query\/queries@ on Elasticsearch 9 (9.1+, experimental).
-- This endpoint does not exist on Elasticsearch 8.x, so the canonical
-- request builder lives only in the ES9 module (and shares its builder
-- with 'getESQLQuery'). The response is keyed on the wire by each
-- query's encoded async-id; this wrapper flattens it into
-- @[(AsyncESQLId, ESQLQueryInfo)]@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-esql-list-queries>.
getESQLQueries ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m [(AsyncESQLId, ESQLQueryInfo)]
getESQLQueries = performBHRequest Requests9.getESQLQueries

-- | 'getTermsEnum' returns a list of terms in a field for auto-complete
-- use cases via @GET \/{index}\/_terms_enum@ on Elasticsearch 9. The
-- wire format is identical to ES 7.10+\/8.x, so the ES8 request builder
-- is reused verbatim (which itself delegates to ES7).
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-terms-enum.html>.
getTermsEnum ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [IndexName] ->
  FieldName ->
  Maybe Text ->
  m TermsEnumResponse
getTermsEnum mIndices field mString =
  performBHRequest $ Requests9.getTermsEnum mIndices field mString

-- | 'getTermsEnumWith' is the fully-parameterised form of
-- 'getTermsEnum' on Elasticsearch 9. Forwards 'TermsEnumOptions' (URI
-- parameters) and a full 'TermsEnumRequest' body.
--
-- For more information see
-- <https://www.elastic.co/guide/en/elasticsearch/reference/current/search-terms-enum.html>.
getTermsEnumWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [IndexName] ->
  TermsEnumOptions ->
  TermsEnumRequest ->
  m TermsEnumResponse
getTermsEnumWith mIndices opts req =
  performBHRequest $ Requests9.getTermsEnumWith mIndices opts req

-- | 'getStreamsStatus' returns the enabled state of every named stream
-- (e.g. @logs@, @logs.otel@, @logs.ecs@) via @GET /_streams/status@
-- (Elasticsearch 9.1+, experimental). The result is a
-- 'StreamsStatusResponse' map; use 'streamStatusFor' to look up a
-- specific stream. Equivalent to
-- @'getStreamsStatusWith' 'defaultGetStreamsStatusOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-streams-status>.
getStreamsStatus ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m StreamsStatusResponse
getStreamsStatus = getStreamsStatusWith defaultGetStreamsStatusOptions

-- | 'getStreamsStatusWith' is the fully-parameterised variant of
-- 'getStreamsStatus', forwarding the @master_timeout@ query parameter
-- via 'GetStreamsStatusOptions'.
getStreamsStatusWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GetStreamsStatusOptions ->
  m StreamsStatusResponse
getStreamsStatusWith opts =
  performBHRequest $ Requests9.getStreamsStatusWith opts

-- | 'enableStream' enables a named stream via
-- @POST /_streams/{name}/_enable@ (Elasticsearch 9.1+, experimental).
-- Returns 'Acknowledged' on success. Equivalent to
-- @'enableStreamWith' name 'defaultStreamsActionOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-streams-logs-enable>.
enableStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  StreamName ->
  m Acknowledged
enableStream name = performBHRequest $ Requests9.enableStream name

-- | 'enableStreamWith' is the fully-parameterised variant of
-- 'enableStream', forwarding the @master_timeout@ \/ @timeout@ query
-- parameters via 'StreamsActionOptions'.
enableStreamWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  StreamName ->
  StreamsActionOptions ->
  m Acknowledged
enableStreamWith name opts =
  performBHRequest $ Requests9.enableStreamWith name opts

-- | 'disableStream' disables a named stream via
-- @POST /_streams/{name}/_disable@ (Elasticsearch 9.1+, experimental).
-- Returns 'Acknowledged' on success. Equivalent to
-- @'disableStreamWith' name 'defaultStreamsActionOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-streams-logs-disable>.
disableStream ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  StreamName ->
  m Acknowledged
disableStream name = performBHRequest $ Requests9.disableStream name

-- | 'disableStreamWith' is the fully-parameterised variant of
-- 'disableStream', forwarding the @master_timeout@ \/ @timeout@ query
-- parameters via 'StreamsActionOptions'.
disableStreamWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  StreamName ->
  StreamsActionOptions ->
  m Acknowledged
disableStreamWith name opts =
  performBHRequest $ Requests9.disableStreamWith name opts

-- | 'downsampleIndex' rolls up an existing time-series index into a new,
-- coarser-grained index via
-- @POST /{index}/_downsample/{target_index}@ (Elasticsearch 9.x). The
-- @targetIndex@ names the new downsampled index (mandatory path
-- segment). The 'DownsampleRequest' carries the rollup 'FixedInterval'
-- and the optional @sampling_method@. Equivalent to
-- @'downsampleIndexWith' index targetIndex body 'defaultDownsampleOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-indices-downsample>.
downsampleIndex ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  IndexName ->
  DownsampleRequest ->
  m DownsampleResponse
downsampleIndex index targetIndex body =
  performBHRequest $ Requests9.downsampleIndex index targetIndex body

-- | 'downsampleIndexWith' is the fully-parameterised variant of
-- 'downsampleIndex', forwarding the @wait_for_active_shards@,
-- @master_timeout@ and @timeout@ query parameters via 'DownsampleOptions'.
downsampleIndexWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  IndexName ->
  DownsampleRequest ->
  DownsampleOptions ->
  m DownsampleResponse
downsampleIndexWith index targetIndex body opts =
  performBHRequest $ Requests9.downsampleIndexWith index targetIndex body opts

-- | 'getGeoIpStats' returns GeoIP downloader statistics via
-- @GET /_ingest/geoip/stats@: aggregate download counts plus the
-- per-node list of cached database files.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ingest-geo-ip-stats>.
getGeoIpStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m GeoIpStatsResponse
getGeoIpStats = performBHRequest Requests9.getGeoIpStats

-- | 'getGeoIpDatabases' returns every GeoIP database configuration via
-- @GET /_ingest/geoip/database@. For a single id use 'getGeoIpDatabase'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ingest-get-geoip-database>.
getGeoIpDatabases ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m GeoIpDatabasesResponse
getGeoIpDatabases = performBHRequest Requests9.getGeoIpDatabases

-- | 'getGeoIpDatabase' returns one or more GeoIP database
-- configurations via @GET /_ingest/geoip/database/{id}@. The
-- 'GeoIpDatabaseId' may be a single id, a comma-separated list, or the
-- wildcard @"*"@.
getGeoIpDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  m GeoIpDatabasesResponse
getGeoIpDatabase = performBHRequest . Requests9.getGeoIpDatabase

-- | 'putGeoIpDatabase' creates or updates a GeoIP database configuration
-- via @PUT /_ingest/geoip/database/{id}@. The 'GeoIpDatabasePutBody'
-- carries the required @maxmind@ provider. Returns 'Acknowledged' on
-- success.
putGeoIpDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  GeoIpDatabasePutBody ->
  m Acknowledged
putGeoIpDatabase dbId body =
  performBHRequest $ Requests9.putGeoIpDatabase dbId body

-- | 'deleteGeoIpDatabase' deletes one or more GeoIP database
-- configurations via @DELETE /_ingest/geoip/database/{id}@. The
-- 'GeoIpDatabaseId' may be a single id, a comma-separated list, or the
-- wildcard @"*"@.
deleteGeoIpDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  m Acknowledged
deleteGeoIpDatabase = performBHRequest . Requests9.deleteGeoIpDatabase

-- | 'getIpLocationDatabases' returns every IP-location database
-- configuration via @GET /_ingest/ip_location/database@.
getIpLocationDatabases ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m GeoIpDatabasesResponse
getIpLocationDatabases =
  performBHRequest Requests9.getIpLocationDatabases

-- | 'getIpLocationDatabase' returns one or more IP-location database
-- configurations via @GET /_ingest/ip_location/database/{id}@.
getIpLocationDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  m GeoIpDatabasesResponse
getIpLocationDatabase = performBHRequest . Requests9.getIpLocationDatabase

-- | 'putIpLocationDatabase' creates or updates an IP-location database
-- configuration via @PUT /_ingest/ip_location/database/{id}@. The
-- 'IpLocationDatabasePutBody' should carry exactly one of @maxmind@ or
-- @ipinfo@. Returns 'Acknowledged' on success.
putIpLocationDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  IpLocationDatabasePutBody ->
  m Acknowledged
putIpLocationDatabase dbId body =
  performBHRequest $ Requests9.putIpLocationDatabase dbId body

-- | 'deleteIpLocationDatabase' deletes one or more IP-location database
-- configurations via @DELETE /_ingest/ip_location/database/{id}@.
deleteIpLocationDatabase ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  GeoIpDatabaseId ->
  m Acknowledged
deleteIpLocationDatabase =
  performBHRequest . Requests9.deleteIpLocationDatabase

-- | 'simulateIngest' runs the simulate-ingest v2 pipeline resolution
-- against the supplied documents via @POST /_ingest/_simulate@.
-- Equivalent to @'simulateIngestWith' body 'defaultSimulateIngestOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-simulate-ingest>.
simulateIngest ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SimulateIngestRequest ->
  m SimulateIngestResponse
simulateIngest body =
  performBHRequest $ Requests9.simulateIngest body

-- | 'simulateIngestWith' is the fully-parameterised variant of
-- 'simulateIngest', forwarding the @pipeline@ and @merge_type@ query
-- parameters via 'SimulateIngestOptions'.
simulateIngestWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SimulateIngestRequest ->
  SimulateIngestOptions ->
  m SimulateIngestResponse
simulateIngestWith body opts =
  performBHRequest $ Requests9.simulateIngestWith body opts

-- | 'simulateIngestIndex' runs the index-scoped simulate-ingest v2
-- resolution via @POST /_ingest/{index}/_simulate@. Equivalent to
-- @'simulateIngestIndexWith' indexName body 'defaultSimulateIngestOptions'@.
simulateIngestIndex ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  SimulateIngestRequest ->
  m SimulateIngestResponse
simulateIngestIndex indexName body =
  performBHRequest $ Requests9.simulateIngestIndex indexName body

-- | 'simulateIngestIndexWith' is the fully-parameterised variant of
-- 'simulateIngestIndex', forwarding the @pipeline@ and @merge_type@
-- query parameters via 'SimulateIngestOptions'.
simulateIngestIndexWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  SimulateIngestRequest ->
  SimulateIngestOptions ->
  m SimulateIngestResponse
simulateIngestIndexWith indexName body opts =
  performBHRequest $ Requests9.simulateIngestIndexWith indexName body opts

-- | 'simulateIngestGet' is the GET-form counterpart of 'simulateIngest',
-- running the simulate-ingest v2 pipeline resolution against the
-- supplied documents via @GET /_ingest/_simulate@. The Elasticsearch
-- operation documents both GET and POST for this path; they are
-- semantically identical (the body is sent with the GET). Prefer
-- 'simulateIngest' (POST) unless a GET is specifically required.
-- Equivalent to @'simulateIngestWithGet' body 'defaultSimulateIngestOptions'@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-simulate-ingest>.
simulateIngestGet ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SimulateIngestRequest ->
  m SimulateIngestResponse
simulateIngestGet body =
  performBHRequest $ Requests9.simulateIngestGet body

-- | 'simulateIngestWithGet' is the fully-parameterised GET-form variant
-- of 'simulateIngestGet', forwarding the @pipeline@ and @merge_type@
-- query parameters via 'SimulateIngestOptions'.
simulateIngestWithGet ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  SimulateIngestRequest ->
  SimulateIngestOptions ->
  m SimulateIngestResponse
simulateIngestWithGet body opts =
  performBHRequest $ Requests9.simulateIngestWithGet body opts

-- | 'simulateIngestIndexGet' is the GET-form counterpart of
-- 'simulateIngestIndex', running the index-scoped simulate-ingest v2
-- resolution via @GET /_ingest/{index}/_simulate@. See
-- 'simulateIngestGet' for the GET/POST equivalence note. Equivalent to
-- @'simulateIngestIndexWithGet' indexName body 'defaultSimulateIngestOptions'@.
simulateIngestIndexGet ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  SimulateIngestRequest ->
  m SimulateIngestResponse
simulateIngestIndexGet indexName body =
  performBHRequest $ Requests9.simulateIngestIndexGet indexName body

-- | 'simulateIngestIndexWithGet' is the fully-parameterised GET-form
-- variant of 'simulateIngestIndexGet', forwarding the @pipeline@ and
-- @merge_type@ query parameters via 'SimulateIngestOptions'.
simulateIngestIndexWithGet ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  SimulateIngestRequest ->
  SimulateIngestOptions ->
  m SimulateIngestResponse
simulateIngestIndexWithGet indexName body opts =
  performBHRequest $ Requests9.simulateIngestIndexWithGet indexName body opts

-- | 'resolveCluster' resolves the cluster-alias component of index
-- expressions via @GET /_resolve/cluster[\/{name}]@ on Elasticsearch 9.
-- See 'Requests9.resolveCluster' for the request-builder semantics.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-indices-resolve-cluster>.
resolveCluster ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [Text] ->
  m ResolveClusterResponse
resolveCluster = performBHRequest . Requests9.resolveCluster

-- | 'resolveClusterWith' is the fully-parameterised form of
-- 'resolveCluster'.
resolveClusterWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  ResolveClusterOptions ->
  Maybe [Text] ->
  m ResolveClusterResponse
resolveClusterWith opts mPatterns =
  performBHRequest $ Requests9.resolveClusterWith opts mPatterns

-- | 'getHealthReport' fetches the cluster health summary via
-- @GET /_health_report[\/{feature}]@ on Elasticsearch 9. See
-- 'Requests9.getHealthReport' for the request-builder semantics.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-health-report>.
getHealthReport ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe [Text] ->
  m HealthReport
getHealthReport = performBHRequest . Requests9.getHealthReport

-- | 'getHealthReportWith' is the fully-parameterised form of
-- 'getHealthReport'.
getHealthReportWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  HealthReportOptions ->
  Maybe [Text] ->
  m HealthReport
getHealthReportWith opts mFeatures =
  performBHRequest $ Requests9.getHealthReportWith opts mFeatures

-- | 'getFeatures' lists the installed features via @GET /_features@ on
-- Elasticsearch 9.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-features-get-features>.
getFeatures ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m FeaturesResponse
getFeatures = performBHRequest Requests9.getFeatures

-- | 'getFeaturesWith' is the fully-parameterised form of 'getFeatures'.
getFeaturesWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  FeaturesOptions ->
  m FeaturesResponse
getFeaturesWith opts =
  performBHRequest $ Requests9.getFeaturesWith opts

-- | 'resetFeatures' resets the state of every feature via
-- @POST /_features/_reset@ on Elasticsearch 9. This endpoint is
-- experimental and mutating — intended for development/testing clusters.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-features-reset-features>.
resetFeatures ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  m ResetFeaturesResponse
resetFeatures = performBHRequest Requests9.resetFeatures

-- | 'resetFeaturesWith' is the fully-parameterised form of 'resetFeatures'.
resetFeaturesWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  FeaturesOptions ->
  m ResetFeaturesResponse
resetFeaturesWith opts =
  performBHRequest $ Requests9.resetFeaturesWith opts

------------------------------------------------------------------------------
-- Migration reindex (/_migration/reindex, /_create_from)
------------------------------------------------------------------------------

-- | 'migrateReindex' reindexes all legacy backing indices of a data
-- stream via @POST /_migration/reindex@ (ES 8.18+, identical wire format
-- in ES9). The reindex runs in a persistent task; the endpoint returns
-- 'Acknowledged' immediately. Poll 'getMigrateReindexStatus' to observe
-- progress. Mutates cluster state — call deliberately.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-indices-migrate-reindex>.
migrateReindex ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MigrateReindexRequest ->
  m Acknowledged
migrateReindex req = performBHRequest $ Requests9.migrateReindex req

-- | 'cancelMigrateReindex' cancels an in-progress migration reindex
-- attempt via @POST /_migration/reindex/{index}/_cancel@ (ES 8.18+,
-- identical wire format in ES9). Returns 'Acknowledged' on success.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-indices-cancel-migrate-reindex>.
cancelMigrateReindex ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  NonEmpty IndexName ->
  m Acknowledged
cancelMigrateReindex indices =
  performBHRequest $ Requests9.cancelMigrateReindex indices

-- | 'getMigrateReindexStatus' reports the status of a migration reindex
-- attempt via @GET /_migration/reindex/{index}/_status@ (ES 8.18+,
-- identical wire format in ES9). The response is decoded into
-- 'MigrateReindexStatus'.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-indices-get-migrate-reindex-status>.
getMigrateReindexStatus ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  NonEmpty IndexName ->
  m MigrateReindexStatus
getMigrateReindexStatus indices =
  performBHRequest $ Requests9.getMigrateReindexStatus indices

-- | 'createIndexFrom' copies the mappings and settings from a source
-- index into a fresh destination index via
-- @POST /_create_from/{source}/{dest}@ (ES 8.18+, identical wire format
-- in ES9), with no overrides. Returns 'CreateIndexFromResponse' on
-- success. Mutates cluster state.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-indices-create-from>.
createIndexFrom ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  IndexName ->
  m CreateIndexFromResponse
createIndexFrom source dest =
  performBHRequest $ Requests9.createIndexFrom source dest

-- | 'createIndexFromWith' is the fully-parameterised variant of
-- 'createIndexFrom', accepting an optional 'CreateIndexFromBody' whose
-- @mappings_override@ and @settings_override@ replace the source values.
createIndexFromWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  IndexName ->
  IndexName ->
  Maybe CreateIndexFromBody ->
  m CreateIndexFromResponse
createIndexFromWith source dest mBody =
  performBHRequest $ Requests9.createIndexFromWith source dest mBody

-- =========================================================================
-- ML data frame analytics (X-Pack)
-- =========================================================================

-- | 'putMlDataFrameAnalytics' creates a data frame analytics job via
-- @PUT /_ml/data_frame/analytics/{id}@ on Elasticsearch 9. See
-- 'Requests9.putMlDataFrameAnalytics' for the request-builder semantics.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-put-data-frame-analytics>.
putMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsPutBody ->
  m Acknowledged
putMlDataFrameAnalytics id' body =
  performBHRequest $ Requests9.putMlDataFrameAnalytics id' body

-- | 'putMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'putMlDataFrameAnalytics'.
putMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsPutBody ->
  MlDataFrameAnalyticsOptions ->
  m Acknowledged
putMlDataFrameAnalyticsWith id' body opts =
  performBHRequest $ Requests9.putMlDataFrameAnalyticsWith id' body opts

-- | 'getMlDataFrameAnalytics' fetches one (or every) data frame
-- analytics job via @GET /_ml/data_frame/analytics[/{id}]@. Pass
-- 'Nothing' for the id to list every job.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-get-data-frame-analytics>.
getMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDataFrameAnalyticsId ->
  m MlDataFrameAnalyticsGetResponse
getMlDataFrameAnalytics = performBHRequest . Requests9.getMlDataFrameAnalytics

-- | 'getMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'getMlDataFrameAnalytics'.
getMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsOptions ->
  m MlDataFrameAnalyticsGetResponse
getMlDataFrameAnalyticsWith mid opts =
  performBHRequest $ Requests9.getMlDataFrameAnalyticsWith mid opts

-- | 'updateMlDataFrameAnalytics' updates a data frame analytics job via
-- @POST /_ml/data_frame/analytics/{id}/_update@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-update-data-frame-analytics>.
updateMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsUpdateBody ->
  m Acknowledged
updateMlDataFrameAnalytics id' body =
  performBHRequest $ Requests9.updateMlDataFrameAnalytics id' body

-- | 'updateMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'updateMlDataFrameAnalytics'.
updateMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsUpdateBody ->
  MlDataFrameAnalyticsOptions ->
  m Acknowledged
updateMlDataFrameAnalyticsWith id' body opts =
  performBHRequest $ Requests9.updateMlDataFrameAnalyticsWith id' body opts

-- | 'deleteMlDataFrameAnalytics' deletes a data frame analytics job via
-- @DELETE /_ml/data_frame/analytics/{id}@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-delete-data-frame-analytics>.
deleteMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  m Acknowledged
deleteMlDataFrameAnalytics = performBHRequest . Requests9.deleteMlDataFrameAnalytics

-- | 'deleteMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'deleteMlDataFrameAnalytics'.
deleteMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsOptions ->
  m Acknowledged
deleteMlDataFrameAnalyticsWith id' opts =
  performBHRequest $ Requests9.deleteMlDataFrameAnalyticsWith id' opts

-- | 'startMlDataFrameAnalytics' starts a data frame analytics job via
-- @POST /_ml/data_frame/analytics/{id}/_start@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-start-data-frame-analytics>.
startMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  m Acknowledged
startMlDataFrameAnalytics = performBHRequest . Requests9.startMlDataFrameAnalytics

-- | 'startMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'startMlDataFrameAnalytics'.
startMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsOptions ->
  m Acknowledged
startMlDataFrameAnalyticsWith id' opts =
  performBHRequest $ Requests9.startMlDataFrameAnalyticsWith id' opts

-- | 'stopMlDataFrameAnalytics' stops a data frame analytics job via
-- @POST /_ml/data_frame/analytics/{id}/_stop@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-stop-data-frame-analytics>.
stopMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  m Acknowledged
stopMlDataFrameAnalytics = performBHRequest . Requests9.stopMlDataFrameAnalytics

-- | 'stopMlDataFrameAnalyticsWith' is the fully-parameterised form of
-- 'stopMlDataFrameAnalytics'.
stopMlDataFrameAnalyticsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsOptions ->
  m Acknowledged
stopMlDataFrameAnalyticsWith id' opts =
  performBHRequest $ Requests9.stopMlDataFrameAnalyticsWith id' opts

-- | 'getMlDataFrameAnalyticsStats' fetches usage statistics for one (or
-- every) data frame analytics job via
-- @GET /_ml/data_frame/analytics/{id}/_stats@. Pass 'Nothing' for the id
-- to fetch stats for every job.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-get-data-frame-analytics-stats>.
getMlDataFrameAnalyticsStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDataFrameAnalyticsId ->
  m MlDataFrameAnalyticsStatsResponse
getMlDataFrameAnalyticsStats =
  performBHRequest . Requests9.getMlDataFrameAnalyticsStats

-- | 'getMlDataFrameAnalyticsStatsWith' is the fully-parameterised form
-- of 'getMlDataFrameAnalyticsStats'.
getMlDataFrameAnalyticsStatsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDataFrameAnalyticsId ->
  MlDataFrameAnalyticsOptions ->
  m MlDataFrameAnalyticsStatsResponse
getMlDataFrameAnalyticsStatsWith mid opts =
  performBHRequest $ Requests9.getMlDataFrameAnalyticsStatsWith mid opts

-- | 'previewMlDataFrameAnalytics' simulates a data frame analytics
-- config via @POST /_ml/data_frame/analytics/_preview@, returning the
-- would-be destination rows.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-preview-data-frame-analytics>.
previewMlDataFrameAnalytics ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDataFrameAnalyticsPreviewRequest ->
  m MlDataFrameAnalyticsPreviewResponse
previewMlDataFrameAnalytics =
  performBHRequest . Requests9.previewMlDataFrameAnalytics

-- =========================================================================
-- ML trained models (X-Pack)
-- =========================================================================

-- | 'putMlTrainedModel' creates a trained model via
-- @PUT /_ml/trained_models/{model_id}@ on Elasticsearch 9. See
-- 'Requests9.putMlTrainedModel' for the request-builder semantics.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-put-trained-model>.
putMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelPutBody ->
  m Acknowledged
putMlTrainedModel id' body =
  performBHRequest $ Requests9.putMlTrainedModel id' body

-- | 'putMlTrainedModelWith' is the fully-parameterised form of
-- 'putMlTrainedModel'.
putMlTrainedModelWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelPutBody ->
  MlTrainedModelOptions ->
  m Acknowledged
putMlTrainedModelWith id' body opts =
  performBHRequest $ Requests9.putMlTrainedModelWith id' body opts

-- | 'getMlTrainedModels' fetches one (or every) trained model via
-- @GET /_ml/trained_models[/{model_id}]@. Pass 'Nothing' to list every
-- model.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-get-trained-models>.
getMlTrainedModels ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlTrainedModelId ->
  m MlTrainedModelsResponse
getMlTrainedModels = performBHRequest . Requests9.getMlTrainedModels

-- | 'getMlTrainedModelsWith' is the fully-parameterised form of
-- 'getMlTrainedModels'.
getMlTrainedModelsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlTrainedModelId ->
  MlTrainedModelOptions ->
  m MlTrainedModelsResponse
getMlTrainedModelsWith mid opts =
  performBHRequest $ Requests9.getMlTrainedModelsWith mid opts

-- | 'getMlTrainedModelDefinition' fetches the (streamed) model definition
-- via @GET /_ml/trained_models/{model_id}/definition@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-get-trained-model-definition>.
getMlTrainedModelDefinition ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m MlTrainedModelDefinition
getMlTrainedModelDefinition =
  performBHRequest . Requests9.getMlTrainedModelDefinition

-- | 'getMlTrainedModelDefinitionWith' is the fully-parameterised form of
-- 'getMlTrainedModelDefinition'.
getMlTrainedModelDefinitionWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m MlTrainedModelDefinition
getMlTrainedModelDefinitionWith id' opts =
  performBHRequest $ Requests9.getMlTrainedModelDefinitionWith id' opts

-- | 'updateMlTrainedModel' updates a trained model's metadata via
-- @POST /_ml/trained_models/{model_id}/_update@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-update-trained-model>.
updateMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelUpdateBody ->
  m Acknowledged
updateMlTrainedModel id' body =
  performBHRequest $ Requests9.updateMlTrainedModel id' body

-- | 'updateMlTrainedModelWith' is the fully-parameterised form of
-- 'updateMlTrainedModel'.
updateMlTrainedModelWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelUpdateBody ->
  MlTrainedModelOptions ->
  m Acknowledged
updateMlTrainedModelWith id' body opts =
  performBHRequest $ Requests9.updateMlTrainedModelWith id' body opts

-- | 'deleteMlTrainedModel' deletes a trained model via
-- @DELETE /_ml/trained_models/{model_id}@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-delete-trained-model>.
deleteMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m Acknowledged
deleteMlTrainedModel = performBHRequest . Requests9.deleteMlTrainedModel

-- | 'deleteMlTrainedModelWith' is the fully-parameterised form of
-- 'deleteMlTrainedModel'.
deleteMlTrainedModelWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m Acknowledged
deleteMlTrainedModelWith id' opts =
  performBHRequest $ Requests9.deleteMlTrainedModelWith id' opts

-- | 'deployMlTrainedModel' deploys a trained model to the native
-- process via @POST /_ml/trained_models/{model_id}/deployment/_deploy@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-deploy-trained-model>.
deployMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m Acknowledged
deployMlTrainedModel = performBHRequest . Requests9.deployMlTrainedModel

-- | 'deployMlTrainedModelWith' is the fully-parameterised form of
-- 'deployMlTrainedModel'.
deployMlTrainedModelWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m Acknowledged
deployMlTrainedModelWith id' opts =
  performBHRequest $ Requests9.deployMlTrainedModelWith id' opts

-- | 'undeployMlTrainedModel' releases a deployed model from memory via
-- @POST /_ml/trained_models/{model_id}/deployment/_undeploy@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-undeploy-trained-model>.
undeployMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m Acknowledged
undeployMlTrainedModel =
  performBHRequest . Requests9.undeployMlTrainedModel

-- | 'undeployMlTrainedModelWith' is the fully-parameterised form of
-- 'undeployMlTrainedModel'.
undeployMlTrainedModelWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m Acknowledged
undeployMlTrainedModelWith id' opts =
  performBHRequest $ Requests9.undeployMlTrainedModelWith id' opts

-- | 'startMlTrainedModelDeployment' starts a model deployment via
-- @POST /_ml/trained_models/{model_id}/deployment/_start@ (the 8.12+
-- alias of 'deployMlTrainedModel').
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-start-trained-model-deployment>.
startMlTrainedModelDeployment ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m Acknowledged
startMlTrainedModelDeployment =
  performBHRequest . Requests9.startMlTrainedModelDeployment

-- | 'startMlTrainedModelDeploymentWith' is the fully-parameterised form
-- of 'startMlTrainedModelDeployment'.
startMlTrainedModelDeploymentWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m Acknowledged
startMlTrainedModelDeploymentWith id' opts =
  performBHRequest $ Requests9.startMlTrainedModelDeploymentWith id' opts

-- | 'stopMlTrainedModelDeployment' stops a model deployment via
-- @POST /_ml/trained_models/{model_id}/deployment/_stop@ (the 8.12+ alias
-- of 'undeployMlTrainedModel').
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-stop-trained-model-deployment>.
stopMlTrainedModelDeployment ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  m Acknowledged
stopMlTrainedModelDeployment =
  performBHRequest . Requests9.stopMlTrainedModelDeployment

-- | 'stopMlTrainedModelDeploymentWith' is the fully-parameterised form
-- of 'stopMlTrainedModelDeployment'.
stopMlTrainedModelDeploymentWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelOptions ->
  m Acknowledged
stopMlTrainedModelDeploymentWith id' opts =
  performBHRequest $ Requests9.stopMlTrainedModelDeploymentWith id' opts

-- | 'getMlTrainedModelStats' fetches usage statistics for one (or every)
-- trained model via @GET /_ml/trained_models/{model_id}/_stats@. Pass
-- 'Nothing' to fetch stats for every model.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-get-trained-models-stats>.
getMlTrainedModelStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlTrainedModelId ->
  m MlTrainedModelStatsResponse
getMlTrainedModelStats =
  performBHRequest . Requests9.getMlTrainedModelStats

-- | 'getMlTrainedModelStatsWith' is the fully-parameterised form of
-- 'getMlTrainedModelStats'.
getMlTrainedModelStatsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlTrainedModelId ->
  MlTrainedModelOptions ->
  m MlTrainedModelStatsResponse
getMlTrainedModelStatsWith mid opts =
  performBHRequest $ Requests9.getMlTrainedModelStatsWith mid opts

-- | 'inferMlTrainedModel' runs inference against a deployed model via
-- @POST /_ml/trained_models/{model_id}/_infer@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-infer-trained-model>.
inferMlTrainedModel ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlTrainedModelId ->
  MlTrainedModelInferRequest ->
  m MlTrainedModelInferResponse
inferMlTrainedModel id' req =
  performBHRequest $ Requests9.inferMlTrainedModel id' req

-- =========================================================================
-- ML anomaly jobs (X-Pack)
-- =========================================================================

-- | 'putMlAnomalyJob' creates an anomaly detection job via
-- @PUT /_ml/anomaly_detectors/{job_id}@.
--
-- For more information see
-- <https://www.elastic.co/docs/api/doc/elasticsearch/v9/operation/operation-ml-put-job>.
putMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyJob ->
  m Acknowledged
putMlAnomalyJob id' body =
  performBHRequest $ Requests9.putMlAnomalyJob id' body

-- | 'getMlAnomalyJobs' fetches one (or every) anomaly job via
-- @GET /_ml/anomaly_detectors[/{job_id}]@. Pass 'Nothing' to list every
-- job.
getMlAnomalyJobs ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlJobId ->
  m MlAnomalyJobsResponse
getMlAnomalyJobs = performBHRequest . Requests9.getMlAnomalyJobs

-- | 'getMlAnomalyJobsWith' is the fully-parameterised form of
-- 'getMlAnomalyJobs'.
getMlAnomalyJobsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlJobId ->
  MlAnomalyJobOptions ->
  m MlAnomalyJobsResponse
getMlAnomalyJobsWith mid opts =
  performBHRequest $ Requests9.getMlAnomalyJobsWith mid opts

-- | 'updateMlAnomalyJob' updates an anomaly job via
-- @POST /_ml/anomaly_detectors/{job_id}/_update@.
updateMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyJobUpdate ->
  m Acknowledged
updateMlAnomalyJob id' body =
  performBHRequest $ Requests9.updateMlAnomalyJob id' body

-- | 'deleteMlAnomalyJob' deletes an anomaly job via
-- @DELETE /_ml/anomaly_detectors/{job_id}@.
deleteMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  m Acknowledged
deleteMlAnomalyJob = performBHRequest . Requests9.deleteMlAnomalyJob

-- | 'deleteMlAnomalyJobWith' is the fully-parameterised form of
-- 'deleteMlAnomalyJob'.
deleteMlAnomalyJobWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyJobOptions ->
  m Acknowledged
deleteMlAnomalyJobWith id' opts =
  performBHRequest $ Requests9.deleteMlAnomalyJobWith id' opts

-- | 'openMlAnomalyJob' opens an anomaly job via
-- @POST /_ml/anomaly_detectors/{job_id}/_open@.
openMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  m Acknowledged
openMlAnomalyJob = performBHRequest . Requests9.openMlAnomalyJob

-- | 'closeMlAnomalyJob' closes an anomaly job via
-- @POST /_ml/anomaly_detectors/{job_id}/_close@.
closeMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  m Acknowledged
closeMlAnomalyJob = performBHRequest . Requests9.closeMlAnomalyJob

-- | 'forecastMlAnomalyJob' produces a forecast for a started job via
-- @POST /_ml/anomaly_detectors/{job_id}/_forecast@.
forecastMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlForecastOptions ->
  m MlForecastResponse
forecastMlAnomalyJob id' opts =
  performBHRequest $ Requests9.forecastMlAnomalyJob id' opts

-- | 'flushMlAnomalyJob' flushes interim results via
-- @POST /_ml/anomaly_detectors/{job_id}/_flush@.
flushMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlFlushOptions ->
  m MlFlushResponse
flushMlAnomalyJob id' opts =
  performBHRequest $ Requests9.flushMlAnomalyJob id' opts

-- | 'validateMlAnomalyJob' validates a job configuration via
-- @POST /_ml/anomaly_detectors/_validate@ without creating it.
validateMlAnomalyJob ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlAnomalyJob ->
  m MlValidateResponse
validateMlAnomalyJob = performBHRequest . Requests9.validateMlAnomalyJob

-- | 'getMlAnomalyJobStats' fetches usage statistics for one (or every)
-- anomaly job via @GET /_ml/anomaly_detectors[/{job_id}]/_stats@.
getMlAnomalyJobStats ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlJobId ->
  m MlAnomalyJobStatsResponse
getMlAnomalyJobStats =
  performBHRequest . Requests9.getMlAnomalyJobStats

-- | 'getMlAnomalyJobStatsWith' is the fully-parameterised form of
-- 'getMlAnomalyJobStats'.
getMlAnomalyJobStatsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlJobId ->
  MlAnomalyJobOptions ->
  m MlAnomalyJobStatsResponse
getMlAnomalyJobStatsWith mid opts =
  performBHRequest $ Requests9.getMlAnomalyJobStatsWith mid opts

-- | 'getMlAnomalyJobResults' fetches read-only results
-- (buckets\/records\/categories\/influencers\/overall_buckets) via
-- @GET /_ml/anomaly_detectors/{job_id}/_results/{kind}@.
getMlAnomalyJobResults ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyResultType ->
  m MlAnomalyJobResults
getMlAnomalyJobResults id' kind =
  performBHRequest $ Requests9.getMlAnomalyJobResults id' kind

-- | 'getMlAnomalyJobResultsWith' is the fully-parameterised form of
-- 'getMlAnomalyJobResults'.
getMlAnomalyJobResultsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyResultType ->
  MlAnomalyJobOptions ->
  m MlAnomalyJobResults
getMlAnomalyJobResultsWith id' kind opts =
  performBHRequest $ Requests9.getMlAnomalyJobResultsWith id' kind opts

-- | 'getMlModelSnapshots' lists model snapshots for a job via
-- @GET /_ml/anomaly_detectors/{job_id}/_model_snapshots@.
getMlModelSnapshots ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  m MlModelSnapshotsResponse
getMlModelSnapshots = performBHRequest . Requests9.getMlModelSnapshots

-- | 'getMlModelSnapshotsWith' is the fully-parameterised form of
-- 'getMlModelSnapshots'.
getMlModelSnapshotsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlAnomalyJobOptions ->
  m MlModelSnapshotsResponse
getMlModelSnapshotsWith id' opts =
  performBHRequest $ Requests9.getMlModelSnapshotsWith id' opts

-- | 'getMlModelSnapshot' fetches a single model snapshot via
-- @GET /_ml/anomaly_detectors/{job_id}/_model_snapshots/{snapshot_id}@.
getMlModelSnapshot ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  m MlModelSnapshotsResponse
getMlModelSnapshot id' snap =
  performBHRequest $ Requests9.getMlModelSnapshot id' snap

-- | 'getMlModelSnapshotWith' is the fully-parameterised form of
-- 'getMlModelSnapshot'.
getMlModelSnapshotWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  MlAnomalyJobOptions ->
  m MlModelSnapshotsResponse
getMlModelSnapshotWith id' snap opts =
  performBHRequest $ Requests9.getMlModelSnapshotWith id' snap opts

-- | 'updateMlModelSnapshot' updates snapshot metadata via
-- @PUT /_ml/anomaly_detectors/{job_id}/_model_snapshots/{snapshot_id}@.
updateMlModelSnapshot ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  Value ->
  m Acknowledged
updateMlModelSnapshot id' snap body =
  performBHRequest $ Requests9.updateMlModelSnapshot id' snap body

-- | 'deleteMlModelSnapshot' deletes a model snapshot via
-- @DELETE /_ml/anomaly_detectors/{job_id}/_model_snapshots/{snapshot_id}@.
deleteMlModelSnapshot ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  m Acknowledged
deleteMlModelSnapshot id' snap =
  performBHRequest $ Requests9.deleteMlModelSnapshot id' snap

-- | 'deleteMlModelSnapshotWith' is the fully-parameterised form of
-- 'deleteMlModelSnapshot'.
deleteMlModelSnapshotWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  MlAnomalyJobOptions ->
  m Acknowledged
deleteMlModelSnapshotWith id' snap opts =
  performBHRequest $ Requests9.deleteMlModelSnapshotWith id' snap opts

-- | 'revertMlModelSnapshot' reverts a job to a model snapshot via
-- @POST /_ml/anomaly_detectors/{job_id}/_model_snapshots/{snapshot_id}/_revert@.
revertMlModelSnapshot ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  Value ->
  m MlRevertSnapshotResponse
revertMlModelSnapshot id' snap body =
  performBHRequest $ Requests9.revertMlModelSnapshot id' snap body

-- | 'revertMlModelSnapshotWith' is the fully-parameterised form of
-- 'revertMlModelSnapshot'.
revertMlModelSnapshotWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlJobId ->
  MlModelSnapshotId ->
  Value ->
  MlAnomalyJobOptions ->
  m MlRevertSnapshotResponse
revertMlModelSnapshotWith id' snap body opts =
  performBHRequest $ Requests9.revertMlModelSnapshotWith id' snap body opts

-- =========================================================================
-- ML datafeeds (X-Pack)
-- =========================================================================

-- | 'putMlDatafeed' creates a datafeed via
-- @PUT /_ml/datafeeds/{feed_id}@.
putMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  MlDatafeed ->
  m Acknowledged
putMlDatafeed id' body =
  performBHRequest $ Requests9.putMlDatafeed id' body

-- | 'getMlDatafeeds' fetches one (or every) datafeed via
-- @GET /_ml/datafeeds[/{feed_id}]@.
getMlDatafeeds ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDatafeedId ->
  m MlDatafeedsResponse
getMlDatafeeds = performBHRequest . Requests9.getMlDatafeeds

-- | 'getMlDatafeedsWith' is the fully-parameterised form of
-- 'getMlDatafeeds'.
getMlDatafeedsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlDatafeedId ->
  MlDatafeedOptions ->
  m MlDatafeedsResponse
getMlDatafeedsWith mid opts =
  performBHRequest $ Requests9.getMlDatafeedsWith mid opts

-- | 'updateMlDatafeed' updates a datafeed via
-- @POST /_ml/datafeeds/{feed_id}/_update@.
updateMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  MlDatafeedUpdate ->
  m Acknowledged
updateMlDatafeed id' body =
  performBHRequest $ Requests9.updateMlDatafeed id' body

-- | 'deleteMlDatafeed' deletes a datafeed via
-- @DELETE /_ml/datafeeds/{feed_id}@.
deleteMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  m Acknowledged
deleteMlDatafeed = performBHRequest . Requests9.deleteMlDatafeed

-- | 'startMlDatafeed' starts a datafeed via
-- @POST /_ml/datafeeds/{feed_id}/_start@. The body may carry optional
-- @start@ \/ @end@ times; pass @object []@ for an empty body.
startMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  Value ->
  m Acknowledged
startMlDatafeed id' body =
  performBHRequest $ Requests9.startMlDatafeed id' body

-- | 'stopMlDatafeed' stops a datafeed via
-- @POST /_ml/datafeeds/{feed_id}/_stop@.
stopMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  m Acknowledged
stopMlDatafeed = performBHRequest . Requests9.stopMlDatafeed

-- | 'previewMlDatafeed' previews the documents a datafeed would send via
-- @GET /_ml/datafeeds/{feed_id}/_preview@.
previewMlDatafeed ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlDatafeedId ->
  m MlDatafeedPreviewResponse
previewMlDatafeed = performBHRequest . Requests9.previewMlDatafeed

-- =========================================================================
-- ML filters (X-Pack)
-- =========================================================================

-- | 'putMlFilter' creates or updates a filter via
-- @PUT /_ml/filters/{filter_id}@.
putMlFilter ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlFilterId ->
  MlFilter ->
  m Acknowledged
putMlFilter id' body =
  performBHRequest $ Requests9.putMlFilter id' body

-- | 'getMlFilters' fetches one (or every) filter via
-- @GET /_ml/filters[/{filter_id}]@.
getMlFilters ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlFilterId ->
  m MlFiltersResponse
getMlFilters = performBHRequest . Requests9.getMlFilters

-- | 'getMlFiltersWith' is the fully-parameterised form of 'getMlFilters'.
getMlFiltersWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlFilterId ->
  MlDatafeedOptions ->
  m MlFiltersResponse
getMlFiltersWith mid opts =
  performBHRequest $ Requests9.getMlFiltersWith mid opts

-- | 'deleteMlFilter' deletes a filter via
-- @DELETE /_ml/filters/{filter_id}@.
deleteMlFilter ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlFilterId ->
  m Acknowledged
deleteMlFilter = performBHRequest . Requests9.deleteMlFilter

-- =========================================================================
-- ML calendars and scheduled events (X-Pack)
-- =========================================================================

-- | 'putMlCalendar' creates or updates a calendar via
-- @PUT /_ml/calendars/{calendar_id}@.
putMlCalendar ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlCalendarId ->
  MlCalendar ->
  m Acknowledged
putMlCalendar id' body =
  performBHRequest $ Requests9.putMlCalendar id' body

-- | 'getMlCalendars' fetches one (or every) calendar via
-- @GET /_ml/calendars[/{calendar_id}]@.
getMlCalendars ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlCalendarId ->
  m MlCalendarsResponse
getMlCalendars = performBHRequest . Requests9.getMlCalendars

-- | 'getMlCalendarsWith' is the fully-parameterised form of
-- 'getMlCalendars'.
getMlCalendarsWith ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  Maybe MlCalendarId ->
  MlDatafeedOptions ->
  m MlCalendarsResponse
getMlCalendarsWith mid opts =
  performBHRequest $ Requests9.getMlCalendarsWith mid opts

-- | 'deleteMlCalendar' deletes a calendar via
-- @DELETE /_ml/calendars/{calendar_id}@.
deleteMlCalendar ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlCalendarId ->
  m Acknowledged
deleteMlCalendar = performBHRequest . Requests9.deleteMlCalendar

-- | 'setMlScheduledEvents' adds (or replaces) scheduled events on a
-- calendar via @POST /_ml/calendars/{calendar_id}/events@.
setMlScheduledEvents ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlCalendarId ->
  MlScheduledEvents ->
  m MlScheduledEventsResponse
setMlScheduledEvents id' body =
  performBHRequest $ Requests9.setMlScheduledEvents id' body

-- | 'getMlScheduledEvents' lists the scheduled events on a calendar via
-- @GET /_ml/calendars/{calendar_id}/events@.
getMlScheduledEvents ::
  (MonadBH m, WithBackend ElasticSearch9 m) =>
  MlCalendarId ->
  m MlScheduledEventsResponse
getMlScheduledEvents = performBHRequest . Requests9.getMlScheduledEvents