o
    gZhS1                    @   sH   d dl Zd dlmZ ddlmZ ddlmZmZm	Z	 G dd deZ
dS )    N)ObjectApiResponse   )NamespacedClient)SKIP_IN_PATH_quote_rewrite_parametersc                5   @   sx1  e Zd Ze ddddddedeje dejejeej	e f  deje deje de
ej fd	d
Zedddddddddddedeje deje dejejeej	e f  deje deje deje dejejddef  de
ej fddZe ddddddedeje dejejeej	e f  deje deje de
ej fddZe ddddddededeje dejejeej	e f  deje deje de
ej fddZe ddddddedejeej	e f deje dejejeej	e f  deje deje de
ej fddZe ddddddddedeje dejejeej	e f  deje deje deje dejejddef  de
ej fd d!Ze dddddd"d#edeje dejejeej	e f  deje deje deje de
ej fd$d%Zedddddddddd&deje deje dejejeej	e f  deje deje d'eje dejejddef  de
ej fd(d)Ze dddddd*edeje dejejeej	e f  deje deje de
ej fd+d,Ze dddddddd-ded.eje d/eje deje dejejeej	e f  deje deje dejejddef  de
ej fd0d1Ze dddddddd2ded3eje deje dejejeej	e f  deje deje deje d4eje de
ej fd5d6Ze dddddded7edeje dejejeej	e f  deje deje de
ej fd8d9Ze dddddd"dedeje dejejeej	e f  deje deje deje de
ej fd:d;Ze dddddded<edeje dejejeej	e f  deje deje de
ej fd=d>Zedddddddddd?d@ejejeejf  deje dejejeej	e f  deje dAejejeef  dBejejeef  deje de
ej fdCdDZeddddddddEdFejeejf dGedeje dejejeej	e f  deje deje dHejejeejf  de
ej fdIdJZeddddddddddddddddKdeje dLeje dMejejeejf  dNejejeejf  dOeje dPejejeejf  deje dejejeej	e f  deje dQeje dReje deje dSejejeejf  de
ej fdTdUZeddddddddddddV	dedWejejeejf  dXeje dYejejeejf  deje dejejeej	e f  deje deje dZejejeejf  d[ejejeejf  de
ej fd\d]Z edddddddddd^ded_ejejddef  deje d`ejejddef  dejejeej	e f  deje daeje deje de
ej fdbdcZ!eddddeidfddddddddddddddddgdedhejejeejf  dieje djeje dYejejeejf  deje dkeje dleje dejejeej	e f  deeje deje dmejejeejf  deje dneje doeje d[ejejeejf  de
ej f"dpdqZ"edddeidrdddddddddds	dedYejejeejf  deje dejejeej	e f  deeje deje deje deje dneje d[ejejeejf  de
ej fdtduZ#eddddeidfdddddddddvdeje deje dejejeej	e f  deeje deje dmejejeejf  deje dneje de
ej fdwdxZ$eddddeidfddddddddddy	dedzeje deje dejejeej	e f  deeje deje dmejejeejf  d{eje deje dneje de
ej fd|d}Z%edddeidrdddddddddd~	deje deje deje deje dejejeej	e f  deeje deje deje dneje de
ej fddZ&edddeidrdddddddddd	deje deje deje dejejeej	e f  deeje deje deje dneje deje de
ej fddZ'e dddddddd#ejejeej	e f  deje deje dejejeej	e f  deje deje de
ej fddZ(e ddddddddd#ejejeej	e f  deje deje deje dejejeej	e f  deje deje de
ej fddZ)edddeidrddddddddd*ejejeej	e f  deje dejejeej	e f  deeje deje deje dneje de
ej fddZ*eddddeidfdddddddddddddddedjeje dYejejeejf  deje dkeje dejejeej	e f  deeje deje deje dmejejeejf  deje dneje doeje d[ejejeejf  de
ej fddZ+e ddddddddeje deje deje dejejeej	e f  deje deje de
ej fddZ,e dddddddddejejeej	e f  deje deje deje dejejeej	e f  deje deje de
ej fddZ-e dddddddddeje deje dejejeej	e f  deje dejejddef  deje dejejddef  de
ej fddZ.e ddddddded7edeje deje dejejeej	e f  deje deje de
ej fddZ/eddddeidfdddddddddddddded7eje djeje dYejejeejf  deje dejejeej	e f  deeje deje dmejejeejf  deje dneje doeje d[ejejeejf  de
ej fddZ0edddddddddddddddedeje dejejddef  dYejejeejf  deje dkeje dejejeej	e f  deje dejejeef  deje d[ejejeejf  deje de
ej fddZ1eddddeidfdddddddddddddddedjeje dYejejeejf  deje dkeje dejejeej	e f  deeje deje dmejejeejf  deje deje dneje doeje d[ejejeejf  de
ej fddZ2edddeidrddddddddddddddeje deje deje deje deje dejejeej	e f  deeje deje dejejdef  deje dneje deje de
ej fddZ3edddeidrddddddddddejejeej	e f  deje deje dejejeej	e f  deeje deje deje dneje de
ej fddZ4eddddddddddedej	ejeejf  deje dejejeej	e f  deje dejejeejf  deje dejejddef  de
ej fddZ5e ddddddeje dejejeej	e f  deje deje de
ej f
ddZ6edddddddddedeje dejejeej	e f  deje deje dejejddef  de
ej fddZ7eddddddddedej	ejeejf  deje dejejeej	e f  deje deje de
ej fddĄZ8eddƍdddddddǜdedej	ej deje dejejeej	e f  deje deje dejejeejf  dejejeejf  de
ej fdd˄Z9eddddddddd̜deje dejejeejf  deje dejejeej	e f  deje deje de
ej fddτZ:eddddddddddddМ	d#eje dejejeejf  dYejejeejf  deje dejejeej	e f  deje dejejeejf  deje d[ejejeejf  de
ej fddԄZ;eddddddddd՜dedOeje deje dejejeej	e f  deje dejej	e  deje de
ej fdd؄Z<e ddddddededeje dejejeej	e f  deje deje de
ej fddڄZ=eddhd܍ddddddddddddݜdedMejeejf dPejeejf dSejeejf dLeje dNejejeejf  dOeje deje dejejeej	e f  dejejeejeej	e f f  deje dQeje dReje deje deje de
ej f ddZ>eddhd܍ddddddddddddddddddddddddd#edejejeejeejf f  deje dejejeejf  dejejeejf  deje dejejej	ejdef  ejdef f  dejejeej	e f  dejejddef  dejejeejeej	e f f  deje deje deje dejejeej	e f  dejejeej	e f  dejejeejf  deje deje deje dHejejeejf  dejejddef  dejejeejeejf f  dejejeejeejf f  deje de
ej f2ddZ?edddddddddd*edOeje deje dejejeej	e f  deje dejej	e  deje de
ej fddZ@eddddddddddddddddddddded@ejeejf dejeejf deje dejejeejf  dejejddef  dejej deje dejejeejf  dOeje deje dejejeej	e f  d ejej	e  deje dejejeejf  deje deje deje deje deje de
ej f*ddZAeddddddddddddddddddded	eje d
eje dejejeejf  dOeje deje dejejeej	e f  deje dejejeejf  dejejeejf  dejej deje dejejdef  deje deje dejej	e  de
ej f"ddZBe ddddddded<edeje dejejeej	e f  deje deje deje de
ej fddZCeddddddddedededededeje dejejeej	e f  deje deje de
ej fddZDeddddddddddedej	e deje dejejeej	e f  deje dejej	e  deje d ejej	e  de
ej fd!d"ZEe ddddddd#ded3eje deje dejejeej	e f  deje deje d4eje de
ej fd$d%ZFedddddddd&ded7ed'eje deje dejejeej	e f  deje deje de
ej fd(d)ZGe ddddddd*d+eje deje dejejeej	e f  deje deje dejejddef  de
ej fd,d-ZHe dddddddedeje dejejeej	e f  deje deje dejejddef  de
ej fd.d/ZIedddddddddd0d#edYejejeejf  deje dejejeej	e f  deje deje d[ejejeejf  dejejddef  de
ej fd1d2ZJe ddddddddddddd3ded4ejejeef  d5eje deje dejejeej	e f  deje d6eje deje d7ejejd8ef  d9eje d:eje dejejddef  d;ejejd<ef  de
ej fd=d>ZKe dddddddddedeje deje dejejeej	e f  deje deje deje dejejddef  de
ej fd?d@ZLeddddddddddd#edeje deje dejejeej	e f  deje deje deje dejejddef  de
ej fdAdBZMe dddddddCdedeje deje dejejeej	e f  deje deje deje de
ej fdDdEZNedddddddddddFdedLeje dOeje deje dejejeej	e f  deje dQeje dReje deje de
ej fdGdHZOedddddddddddddddddddddddddId#edejejeejeejf f  deje dejejeejf  dejejeejf  deje dejejej	ejdef  ejdef f  dejejeej	e f  dejejddef  deje deje deje dejej	e  dejej	e  dejejeejf  deje deje deje dHejejeejf  dejejddef  dejejeejeejf f  dejejeejeejf f  deje de
ej f0dJdKZPeddddddddddLd*edMejej	e  dOeje deje dejejeej	e f  deje deje dNejej	e  de
ej fdOdPZQeddddddddddddddddddddddQdedeje dejejeejf  dejejddef  dRejej	e  dejejeejf  deje dOeje dSejej	ejeejf   deje dejejeej	e f  d ejej	e  deje dejejeejf  dTejejddef  deje dUejejeejf  deje deje deje de
ej f*dVdWZRedddddddddXded7edOeje deje dejejeej	e f  deje deje dYeje de
ej fdZd[ZSe ddddddd\ded7edeje dejejeej	e f  deje deje dejejddef  d4eje de
ej fd]d^ZTedddddddddddddddd_d@ejejeejf  dejejeejf  dejejeejf  dOeje deje dejejeej	e f  deje deje d`ejejeejf  daeje deje deje deje de
ej fdbdcZUedddƍdddddddejeejf deje dejejeej	e f  deje deje de
ej fdedfZVdS (g  MlClientN)error_tracefilter_pathhumanprettymodel_idr	   r
   r   r   returnc          	      C   s~   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< d	d
i}| jd|||dS )a  
        Clear the cached results from a trained model deployment

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/clear-trained-model-deployment-cache.html>`_

        :param model_id: The unique identifier of the trained model.
        +Empty value passed for parameter 'model_id'/_ml/trained_models/z/deployment/cache/_clearNr	   r
   r   r   acceptapplication/jsonPOSTparamsheadersr   
ValueErrorr   perform_request)	selfr   r	   r
   r   r   _MlClient__path_MlClient__query_MlClient__headers r   T/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/ml.py$clear_trained_model_deployment_cache   s    z-MlClient.clear_trained_model_deployment_cacheT)body_fields)allow_no_matchr	   r
   forcer   r   timeoutjob_idr"   r#   r$   zt.Literal[-1]zt.Literal[0]c                C      |t v rtddt| d}	i }
i }|dur||
d< |dur$||d< |dur,||d< |dur4||
d< |dur<||d	< |durD||d
< |durL||
d< |
sPd}
ddi}|
dur\d|d< | jd|	|||
dS )a  
        Closes one or more anomaly detection jobs. A job can be opened and closed multiple
        times throughout its lifecycle.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-close-job.html>`_

        :param job_id: Identifier for the anomaly detection job. It can be a job identifier,
            a group name, or a wildcard expression. You can close multiple anomaly detection
            jobs in a single API request by using a group name, a comma-separated list
            of jobs, or a wildcard expression. You can close all jobs by using `_all`
            or by specifying `*` as the job identifier.
        :param allow_no_match: Refer to the description for the `allow_no_match` query
            parameter.
        :param force: Refer to the descriptiion for the `force` query parameter.
        :param timeout: Refer to the description for the `timeout` query parameter.
        )Empty value passed for parameter 'job_id'/_ml/anomaly_detectors/z/_closeNr"   r	   r
   r#   r   r   r$   r   r   content-typer   r   r   bodyr   )r   r%   r"   r	   r
   r#   r   r   r$   r   _MlClient__bodyr   r   r   r   r   	close_job=   s6   
zMlClient.close_jobcalendar_idc          	      C   |   |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< dd	i}| jd
|||dS )z
        Deletes a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-calendar.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        .Empty value passed for parameter 'calendar_id'/_ml/calendars/Nr	   r
   r   r   r   r   DELETEr   r   )	r   r.   r	   r
   r   r   r   r   r   r   r   r   delete_calendarx       zMlClient.delete_calendarevent_idc          
      C      |t v rtd|t v rtddt| dt| }i }|dur&||d< |dur.||d< |dur6||d< |dur>||d	< d
di}	| jd|||	dS )a}  
        Deletes scheduled events from a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-calendar-event.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        :param event_id: Identifier for the scheduled event. You can obtain this identifier
            by using the get calendar events API.
        r0   z+Empty value passed for parameter 'event_id'r1   z/events/Nr	   r
   r   r   r   r   r2   r   r   )
r   r.   r5   r	   r
   r   r   r   r   r   r   r   r   delete_calendar_event   $   zMlClient.delete_calendar_eventc          
      C   r6   )a  
        Deletes anomaly detection jobs from a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-calendar-job.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        :param job_id: An identifier for the anomaly detection jobs. It can be a job
            identifier, a group name, or a comma-separated list of jobs or groups.
        r0   r'   r1   /jobs/Nr	   r
   r   r   r   r   r2   r   r   
r   r.   r%   r	   r
   r   r   r   r   r   r   r   r   delete_calendar_job   r8   zMlClient.delete_calendar_job)r	   r
   r#   r   r   r$   idc                C   s   |t v rtddt| }i }	|dur||	d< |dur!||	d< |dur)||	d< |dur1||	d< |dur9||	d< |durA||	d	< d
di}
| jd||	|
dS )a  
        Deletes an existing data frame analytics job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/delete-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job.
        :param force: If `true`, it deletes a job that is not stopped; this method is
            quicker than stopping and deleting the job.
        :param timeout: The time to wait for the job to be deleted.
        %Empty value passed for parameter 'id'/_ml/data_frame/analytics/Nr	   r
   r#   r   r   r$   r   r   r2   r   r   )r   r<   r	   r
   r#   r   r   r$   r   r   r   r   r   r   delete_data_frame_analytics   s(   z$MlClient.delete_data_frame_analytics)r	   r
   r#   r   r   datafeed_idc          
      C      |t v rtddt| }i }|dur||d< |dur!||d< |dur)||d< |dur1||d< |dur9||d< d	d
i}	| jd|||	dS )aA  
        Deletes an existing datafeed.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-datafeed.html>`_

        :param datafeed_id: A numerical character string that uniquely identifies the
            datafeed. This identifier can contain lowercase alphanumeric characters (a-z
            and 0-9), hyphens, and underscores. It must start and end with alphanumeric
            characters.
        :param force: Use to forcefully delete a started datafeed; this method is quicker
            than stopping and deleting the datafeed.
        .Empty value passed for parameter 'datafeed_id'/_ml/datafeeds/Nr	   r
   r#   r   r   r   r   r2   r   r   )
r   r@   r	   r
   r#   r   r   r   r   r   r   r   r   delete_datafeed  s$   zMlClient.delete_datafeed)r%   r	   r
   r   r   requests_per_secondr$   rE   c                C   s   |t vrdt| }nd}i }	i }
|dur||	d< |dur"||	d< |dur*||	d< |dur2||	d< |dur:||
d< |durB||
d	< |
sFd}
d
di}|
durRd|d< | jd||	||
dS )a<  
        Deletes expired and unused machine learning data.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-expired-data.html>`_

        :param job_id: Identifier for an anomaly detection job. It can be a job identifier,
            a group name, or a wildcard expression.
        :param requests_per_second: The desired requests per second for the deletion
            processes. The default behavior is no throttling.
        :param timeout: How long can the underlying delete processes run until they are
            canceled.
        z/_ml/_delete_expired_data/z/_ml/_delete_expired_dataNr	   r
   r   r   rE   r$   r   r   r)   r2   r*   r   r   r   )r   r%   r	   r
   r   r   rE   r$   r   r   r,   r   r   r   r   delete_expired_data=  s2   
zMlClient.delete_expired_data	filter_idc          	      C   r/   )z
        Deletes a filter.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-filter.html>`_

        :param filter_id: A string that uniquely identifies a filter.
        ,Empty value passed for parameter 'filter_id'/_ml/filters/Nr	   r
   r   r   r   r   r2   r   r   )	r   rH   r	   r
   r   r   r   r   r   r   r   r   delete_filterr  r4   zMlClient.delete_filter)forecast_idallow_no_forecastsr	   r
   r   r   r$   rL   rM   c                C   s   |t v rtd|t vr|t vrdt| dt| }	n|t vr*dt| d}	ntdi }
|dur8||
d< |dur@||
d< |durH||
d	< |durP||
d
< |durX||
d< |dur`||
d< ddi}| jd|	|
|dS )a  
        Deletes forecasts from a machine learning job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-forecast.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param forecast_id: A comma-separated list of forecast identifiers. If you do
            not specify this optional parameter or if you specify `_all` or `*` the API
            deletes all forecasts from the job.
        :param allow_no_forecasts: Specifies whether an error occurs when there are no
            forecasts. In particular, if this parameter is set to `false` and there are
            no forecasts associated with the job, attempts to delete all forecasts return
            an error.
        :param timeout: Specifies the period of time to wait for the completion of the
            delete operation. When this period of time elapses, the API fails and returns
            an error.
        r'   r(   z/_forecast/
/_forecast-Couldn't find a path for the given parametersNrM   r	   r
   r   r   r$   r   r   r2   r   r   )r   r%   rL   rM   r	   r
   r   r   r$   r   r   r   r   r   r   delete_forecast  s0   zMlClient.delete_forecast)delete_user_annotationsr	   r
   r#   r   r   wait_for_completionrQ   rR   c                C   s   |t v rtddt| }	i }
|dur||
d< |dur!||
d< |dur)||
d< |dur1||
d< |dur9||
d< |durA||
d	< |durI||
d
< ddi}| jd|	|
|dS )a  
        Deletes an existing anomaly detection job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-job.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param delete_user_annotations: Specifies whether annotations that have been
            added by the user should be deleted along with any auto-generated annotations
            when the job is reset.
        :param force: Use to forcefully delete an opened job; this method is quicker
            than closing and deleting the job.
        :param wait_for_completion: Specifies whether the request should return immediately
            or wait until the job deletion completes.
        r'   r(   NrQ   r	   r
   r#   r   r   rR   r   r   r2   r   r   )r   r%   rQ   r	   r
   r#   r   r   rR   r   r   r   r   r   r   
delete_job  s,   zMlClient.delete_jobsnapshot_idc          
      C   r6   )a  
        Deletes an existing model snapshot.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-delete-snapshot.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: Identifier for the model snapshot.
        r'   .Empty value passed for parameter 'snapshot_id'r(   /model_snapshots/Nr	   r
   r   r   r   r   r2   r   r   )
r   r%   rT   r	   r
   r   r   r   r   r   r   r   r   delete_model_snapshot  $   zMlClient.delete_model_snapshotc          
      C   rA   )a  
        Deletes an existing trained inference model that is currently not referenced
        by an ingest pipeline.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/delete-trained-models.html>`_

        :param model_id: The unique identifier of the trained model.
        :param force: Forcefully deletes a trained model that is referenced by ingest
            pipelines or has a started deployment.
        r   r   Nr	   r
   r#   r   r   r   r   r2   r   r   )
r   r   r	   r
   r#   r   r   r   r   r   r   r   r   delete_trained_model$  s$   zMlClient.delete_trained_modelmodel_aliasc          
      C   r6   )a=  
        Deletes a model alias that refers to the trained model

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/delete-trained-models-aliases.html>`_

        :param model_id: The trained model ID to which the model alias refers.
        :param model_alias: The model alias to delete.
        r   .Empty value passed for parameter 'model_alias'r   /model_aliases/Nr	   r
   r   r   r   r   r2   r   r   )
r   r   rZ   r	   r
   r   r   r   r   r   r   r   r   delete_trained_model_aliasL  rX   z#MlClient.delete_trained_model_alias)analysis_configr	   r
   r   max_bucket_cardinalityoverall_cardinalityr   r^   r_   r`   c                C   s   d}i }	i }
|dur||	d< |dur||
d< |dur||
d< |dur&||
d< |dur.||	d< |dur6||	d< |dur>||
d	< d
d
d}| j d||
||	dS )a  
        Estimates the model memory

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-apis.html>`_

        :param analysis_config: For a list of the properties that you can specify in
            the `analysis_config` component of the body of this API.
        :param max_bucket_cardinality: Estimates of the highest cardinality in a single
            bucket that is observed for influencer fields over the time period that the
            job analyzes data. To produce a good answer, values must be provided for
            all influencer fields. Providing values for fields that are not listed as
            `influencers` has no effect on the estimation.
        :param overall_cardinality: Estimates of the cardinality that is observed for
            fields over the whole time period that the job analyzes data. To produce
            a good answer, values must be provided for fields referenced in the `by_field_name`,
            `over_field_name` and `partition_field_name` of any detectors. Providing
            values for other fields has no effect on the estimation. It can be omitted
            from the request if no detectors have a `by_field_name`, `over_field_name`
            or `partition_field_name`.
        z-/_ml/anomaly_detectors/_estimate_model_memoryNr^   r	   r
   r   r_   r`   r   r   r   r)   r   r*   r   )r   r^   r	   r
   r   r_   r`   r   r   r,   r   r   r   r   r   estimate_model_memoryr  s*   "

zMlClient.estimate_model_memory)r	   r
   r   r   query
evaluationindexrd   c                C   s   |du rt d|du rt dd}i }	i }
|dur||	d< |dur&||	d< |dur.||
d< |dur6||
d< |dur>||
d	< |durF||
d
< |durN||	d< ddd}| jd||
||	dS )a  
        Evaluates the data frame analytics for an annotated index.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/evaluate-dfanalytics.html>`_

        :param evaluation: Defines the type of evaluation you want to perform.
        :param index: Defines the `index` in which the evaluation will be performed.
        :param query: A query clause that retrieves a subset of data from the source
            index.
        Nz-Empty value passed for parameter 'evaluation'z(Empty value passed for parameter 'index'z/_ml/data_frame/_evaluatere   rf   r	   r
   r   r   rd   r   ra   r   r*   r   r   )r   re   rf   r	   r
   r   r   rd   r   r,   r   r   r   r   r   evaluate_data_frame  s2   

zMlClient.evaluate_data_frame)r<   allow_lazy_startanalysisanalyzed_fieldsdescriptiondestr	   r
   r   max_num_threadsmodel_memory_limitr   sourceri   rj   rk   rl   rm   rn   ro   rp   c                C   s  |t vrdt| d}nd}i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d	< |durC||d
< |durK||d< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< |swd}ddi}|durd|d< | jd||||dS )a  
        Explains a data frame analytics config.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/explain-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. This identifier can contain
            lowercase alphanumeric characters (a-z and 0-9), hyphens, and underscores.
            It must start and end with alphanumeric characters.
        :param allow_lazy_start: Specifies whether this job can start when there is insufficient
            machine learning node capacity for it to be immediately assigned to a node.
        :param analysis: The analysis configuration, which contains the information necessary
            to perform one of the following types of analysis: classification, outlier
            detection, or regression.
        :param analyzed_fields: Specify includes and/or excludes patterns to select which
            fields will be included in the analysis. The patterns specified in excludes
            are applied last, therefore excludes takes precedence. In other words, if
            the same field is specified in both includes and excludes, then the field
            will not be included in the analysis.
        :param description: A description of the job.
        :param dest: The destination configuration, consisting of index and optionally
            results_field (ml by default).
        :param max_num_threads: The maximum number of threads to be used by the analysis.
            Using more threads may decrease the time necessary to complete the analysis
            at the cost of using more CPU. Note that the process may use additional threads
            for operational functionality other than the analysis itself.
        :param model_memory_limit: The approximate maximum amount of memory resources
            that are permitted for analytical processing. If your `elasticsearch.yml`
            file contains an `xpack.ml.max_model_memory_limit` setting, an error occurs
            when you try to create data frame analytics jobs that have `model_memory_limit`
            values greater than that setting.
        :param source: The configuration of how to source the analysis data. It requires
            an index. Optionally, query and _source may be specified.
        r>   z	/_explainz"/_ml/data_frame/analytics/_explainNri   rj   rk   rl   rm   r	   r
   r   rn   ro   r   rp   r   r   r)   r   r*   rF   )r   r<   ri   rj   rk   rl   rm   r	   r
   r   rn   ro   r   rp   r   r,   r   r   r   r   r   explain_data_frame_analytics  sJ   5
z%MlClient.explain_data_frame_analytics)	advance_timecalc_interimendr	   r
   r   r   	skip_timestartrr   rs   rt   ru   rv   c       
         C   s   |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |s`d}ddi}|durld|d< | jd||||dS )a  
        Forces any buffered data to be processed by the job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-flush-job.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param advance_time: Refer to the description for the `advance_time` query parameter.
        :param calc_interim: Refer to the description for the `calc_interim` query parameter.
        :param end: Refer to the description for the `end` query parameter.
        :param skip_time: Refer to the description for the `skip_time` query parameter.
        :param start: Refer to the description for the `start` query parameter.
        r'   r(   z/_flushNrr   rs   rt   r	   r
   r   r   ru   rv   r   r   r)   r   r*   r   )r   r%   rr   rs   rt   r	   r
   r   r   ru   rv   r   r,   r   r   r   r   r   	flush_job8  s>   
zMlClient.flush_job)durationr	   
expires_inr
   r   max_model_memoryr   rx   ry   rz   c                C   s   |t v rtddt| d}	i }
i }|dur||
d< |dur$||d< |dur,||
d< |dur4||d< |dur<||d	< |durD||
d
< |durL||d< |
sPd}
ddi}|
dur\d|d< | jd|	|||
dS )az  
        Predicts the future behavior of a time series by using its historical behavior.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-forecast.html>`_

        :param job_id: Identifier for the anomaly detection job. The job must be open
            when you create a forecast; otherwise, an error occurs.
        :param duration: Refer to the description for the `duration` query parameter.
        :param expires_in: Refer to the description for the `expires_in` query parameter.
        :param max_model_memory: Refer to the description for the `max_model_memory`
            query parameter.
        r'   r(   rN   Nrx   r	   ry   r
   r   rz   r   r   r   r)   r   r*   r   )r   r%   rx   r	   ry   r
   r   rz   r   r   r,   r   r   r   r   r   forecastu  s6   
zMlClient.forecastfromfrom_)r!   parameter_aliases)	timestampanomaly_scoredescrt   r	   exclude_interimexpandr
   r}   r   pager   sizesortrv   r   r   r   r   r   r   r   r   c                C   sx  |t v rtd|t vr|t vrdt| dt| }n|t vr*dt| d}ntdi }i }|dur:||d< |durB||d< |durJ||d	< |durR||d
< |durZ||d< |durb||d< |	durj|	|d< |
durr|
|d< |durz||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |sd}ddi}|durd|d< | jd||||dS )a  
        Retrieves anomaly detection job results for one or more buckets.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-bucket.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param timestamp: The timestamp of a single bucket result. If you do not specify
            this parameter, the API returns information about all buckets.
        :param anomaly_score: Refer to the description for the `anomaly_score` query
            parameter.
        :param desc: Refer to the description for the `desc` query parameter.
        :param end: Refer to the description for the `end` query parameter.
        :param exclude_interim: Refer to the description for the `exclude_interim` query
            parameter.
        :param expand: Refer to the description for the `expand` query parameter.
        :param from_: Skips the specified number of buckets.
        :param page:
        :param size: Specifies the maximum number of buckets to obtain.
        :param sort: Refer to the desription for the `sort` query parameter.
        :param start: Refer to the description for the `start` query parameter.
        r'   r(   z/results/buckets/z/results/bucketsrO   Nr   r   rt   r	   r   r   r
   r|   r   r   r   r   r   rv   r   r   r)   r   r*   r   )r   r%   r   r   r   rt   r	   r   r   r
   r}   r   r   r   r   r   rv   r   r,   r   r   r   r   r   get_buckets  sZ   -
zMlClient.get_buckets)r~   )	rt   r	   r
   r}   r   r%   r   r   rv   c       
         C   s   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< |dur:||d	< |durB||d
< |durJ||d< |	durR|	|d< |
durZ|
|d< ddi}| jd|||dS )a  
        Retrieves information about the scheduled events in calendars.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-calendar-event.html>`_

        :param calendar_id: A string that uniquely identifies a calendar. You can get
            information for multiple calendars by using a comma-separated list of ids
            or a wildcard expression. You can get information for all calendars by using
            `_all` or `*` or by omitting the calendar identifier.
        :param end: Specifies to get events with timestamps earlier than this time.
        :param from_: Skips the specified number of events.
        :param job_id: Specifies to get events for a specific anomaly detection job identifier
            or job group. It must be used with a calendar identifier of `_all` or `*`.
        :param size: Specifies the maximum number of events to obtain.
        :param start: Specifies to get events with timestamps after this time.
        r0   r1   /eventsNrt   r	   r
   r|   r   r%   r   r   rv   r   r   GETr   r   )r   r.   rt   r	   r
   r}   r   r%   r   r   rv   r   r   r   r   r   r   get_calendar_events  s4   !zMlClient.get_calendar_events)r.   r	   r
   r}   r   r   r   r   c                C   s   |t vrdt| }	nd}	i }
i }|dur||
d< |dur"||
d< |dur*||
d< |dur2||
d< |dur:||d< |durB||
d	< |durJ||
d
< |sNd}ddi}|durZd|d< | jd|	|
||dS )aw  
        Retrieves configuration information for calendars.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-calendar.html>`_

        :param calendar_id: A string that uniquely identifies a calendar. You can get
            information for multiple calendars by using a comma-separated list of ids
            or a wildcard expression. You can get information for all calendars by using
            `_all` or `*` or by omitting the calendar identifier.
        :param from_: Skips the specified number of calendars. This parameter is supported
            only when you omit the calendar identifier.
        :param page: This object is supported only when you omit the calendar identifier.
        :param size: Specifies the maximum number of calendars to obtain. This parameter
            is supported only when you omit the calendar identifier.
        r1   z/_ml/calendarsNr	   r
   r|   r   r   r   r   r   r   r)   r   r*   rF   )r   r.   r	   r
   r}   r   r   r   r   r   r   r,   r   r   r   r   get_calendarsD  s6   
zMlClient.get_calendars)	category_idr	   r
   r}   r   r   partition_field_valuer   r   r   r   c       
         C   s  |t v rtd|t vr|t vrdt| dt| }n|t vr*dt| d}ntdi }i }|dur:||d< |durB||d< |durJ||d	< |durR||d
< |durZ||d< |durb||d< |	durj|	|d< |
durr|
|d< |svd}ddi}|durd|d< | jd||||dS )a  
        Retrieves anomaly detection job results for one or more categories.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-category.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param category_id: Identifier for the category, which is unique in the job.
            If you specify neither the category ID nor the partition_field_value, the
            API returns information about all categories. If you specify only the partition_field_value,
            it returns information about all categories for the specified partition.
        :param from_: Skips the specified number of categories.
        :param page: Configures pagination. This parameter has the `from` and `size`
            properties.
        :param partition_field_value: Only return categories for the specified partition.
        :param size: Specifies the maximum number of categories to obtain.
        r'   r(   z/results/categories/z/results/categoriesrO   Nr	   r
   r|   r   r   r   r   r   r   r   r)   r   r*   r   )r   r%   r   r	   r
   r}   r   r   r   r   r   r   r   r,   r   r   r   r   get_categories  sB   "
zMlClient.get_categories)	r<   r"   r	   exclude_generatedr
   r}   r   r   r   r   c       	         C   s   |t vrdt| }
nd}
i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< |dur@||d	< |durH||d
< |	durP|	|d< ddi}| jd|
||dS )a  
        Retrieves configuration information for data frame analytics jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. If you do not specify
            this option, the API returns information for the first hundred data frame
            analytics jobs.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no data frame analytics jobs that match. 2. Contains
            the `_all` string or no identifiers and there are no matches. 3. Contains
            wildcard expressions and there are only partial matches. The default value
            returns an empty data_frame_analytics array when there are no matches and
            the subset of results when there are partial matches. If this parameter is
            `false`, the request returns a 404 status code when there are no matches
            or only partial matches.
        :param exclude_generated: Indicates if certain fields should be removed from
            the configuration on retrieval. This allows the configuration to be in an
            acceptable format to be retrieved and then added to another cluster.
        :param from_: Skips the specified number of data frame analytics jobs.
        :param size: Specifies the maximum number of data frame analytics jobs to obtain.
        r>   z/_ml/data_frame/analyticsNr"   r	   r   r
   r|   r   r   r   r   r   r   r   rF   )r   r<   r"   r	   r   r
   r}   r   r   r   r   r   r   r   r   r   get_data_frame_analytics  s0   &z!MlClient.get_data_frame_analytics)	r<   r"   r	   r
   r}   r   r   r   verboser   c       	         C   s   |t vrdt| d}
nd}
i }|dur||d< |dur!||d< |dur)||d< |dur1||d< |dur9||d	< |durA||d
< |durI||d< |	durQ|	|d< ddi}| jd|
||dS )a  
        Retrieves usage information for data frame analytics jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-dfanalytics-stats.html>`_

        :param id: Identifier for the data frame analytics job. If you do not specify
            this option, the API returns information for the first hundred data frame
            analytics jobs.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no data frame analytics jobs that match. 2. Contains
            the `_all` string or no identifiers and there are no matches. 3. Contains
            wildcard expressions and there are only partial matches. The default value
            returns an empty data_frame_analytics array when there are no matches and
            the subset of results when there are partial matches. If this parameter is
            `false`, the request returns a 404 status code when there are no matches
            or only partial matches.
        :param from_: Skips the specified number of data frame analytics jobs.
        :param size: Specifies the maximum number of data frame analytics jobs to obtain.
        :param verbose: Defines whether the stats response should be verbose.
        r>   /_statsz /_ml/data_frame/analytics/_statsNr"   r	   r
   r|   r   r   r   r   r   r   r   r   rF   )r   r<   r"   r	   r
   r}   r   r   r   r   r   r   r   r   r   r   get_data_frame_analytics_stats  s0   $z'MlClient.get_data_frame_analytics_stats)r@   r"   r	   r
   r   r   c          
      C      |t vrdt| d}nd}i }|dur||d< |dur!||d< |dur)||d< |dur1||d< |dur9||d	< d
di}	| jd|||	dS )a  
        Retrieves usage information for datafeeds.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-datafeed-stats.html>`_

        :param datafeed_id: Identifier for the datafeed. It can be a datafeed identifier
            or a wildcard expression. If you do not specify one of these options, the
            API returns information about all datafeeds.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no datafeeds that match. 2. Contains the `_all`
            string or no identifiers and there are no matches. 3. Contains wildcard expressions
            and there are only partial matches. The default value is `true`, which returns
            an empty `datafeeds` array when there are no matches and the subset of results
            when there are partial matches. If this parameter is `false`, the request
            returns a `404` status code when there are no matches or only partial matches.
        rC   r   z/_ml/datafeeds/_statsNr"   r	   r
   r   r   r   r   r   r   rF   )
r   r@   r"   r	   r
   r   r   r   r   r   r   r   r   get_datafeed_statsC  s$   zMlClient.get_datafeed_stats)r@   r"   r	   r   r
   r   r   c                C      |t vrdt| }nd}i }	|dur||	d< |dur ||	d< |dur(||	d< |dur0||	d< |dur8||	d< |dur@||	d	< d
di}
| jd||	|
dS )a  
        Retrieves configuration information for datafeeds.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-datafeed.html>`_

        :param datafeed_id: Identifier for the datafeed. It can be a datafeed identifier
            or a wildcard expression. If you do not specify one of these options, the
            API returns information about all datafeeds.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no datafeeds that match. 2. Contains the `_all`
            string or no identifiers and there are no matches. 3. Contains wildcard expressions
            and there are only partial matches. The default value is `true`, which returns
            an empty `datafeeds` array when there are no matches and the subset of results
            when there are partial matches. If this parameter is `false`, the request
            returns a `404` status code when there are no matches or only partial matches.
        :param exclude_generated: Indicates if certain fields should be removed from
            the configuration on retrieval. This allows the configuration to be in an
            acceptable format to be retrieved and then added to another cluster.
        rC   z/_ml/datafeedsNr"   r	   r   r
   r   r   r   r   r   r   rF   )r   r@   r"   r	   r   r
   r   r   r   r   r   r   r   r   get_datafeedsr  (   zMlClient.get_datafeeds)rH   r	   r
   r}   r   r   r   c                C   r   )aN  
        Retrieves filters.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-filter.html>`_

        :param filter_id: A string that uniquely identifies a filter.
        :param from_: Skips the specified number of filters.
        :param size: Specifies the maximum number of filters to obtain.
        rJ   z/_ml/filtersNr	   r
   r|   r   r   r   r   r   r   r   rF   )r   rH   r	   r
   r}   r   r   r   r   r   r   r   r   r   get_filters  s(   zMlClient.get_filters)r   rt   r	   r   r
   r}   r   influencer_scorer   r   r   r   rv   r   c                C   s,  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |sd}ddi}|durd|d< | jd||||dS )a@  
        Retrieves anomaly detection job results for one or more influencers.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-influencer.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param desc: If true, the results are sorted in descending order.
        :param end: Returns influencers with timestamps earlier than this time. The default
            value means it is unset and results are not limited to specific timestamps.
        :param exclude_interim: If true, the output excludes interim results. By default,
            interim results are included.
        :param from_: Skips the specified number of influencers.
        :param influencer_score: Returns influencers with anomaly scores greater than
            or equal to this value.
        :param page: Configures pagination. This parameter has the `from` and `size`
            properties.
        :param size: Specifies the maximum number of influencers to obtain.
        :param sort: Specifies the sort field for the requested influencers. By default,
            the influencers are sorted by the `influencer_score` value.
        :param start: Returns influencers with timestamps after this time. The default
            value means it is unset and results are not limited to specific timestamps.
        r'   r(   z/results/influencersNr   rt   r	   r   r
   r|   r   r   r   r   r   r   rv   r   r   r)   r   r*   r   )r   r%   r   rt   r	   r   r
   r}   r   r   r   r   r   r   rv   r   r   r,   r   r   r   r   get_influencers  sN   ,
zMlClient.get_influencers)r%   r"   r	   r
   r   r   c          
      C   r   )a"  
        Retrieves usage information for anomaly detection jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-job-stats.html>`_

        :param job_id: Identifier for the anomaly detection job. It can be a job identifier,
            a group name, a comma-separated list of jobs, or a wildcard expression. If
            you do not specify one of these options, the API returns information for
            all anomaly detection jobs.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no jobs that match. 2. Contains the _all string
            or no identifiers and there are no matches. 3. Contains wildcard expressions
            and there are only partial matches. If `true`, the API returns an empty `jobs`
            array when there are no matches and the subset of results when there are
            partial matches. If `false`, the API returns a `404` status code when there
            are no matches or only partial matches.
        r(   r   z/_ml/anomaly_detectors/_statsNr"   r	   r
   r   r   r   r   r   r   rF   )
r   r%   r"   r	   r
   r   r   r   r   r   r   r   r   get_job_stats(  s$   zMlClient.get_job_stats)r%   r"   r	   r   r
   r   r   c                C   r   )a  
        Retrieves configuration information for anomaly detection jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-job.html>`_

        :param job_id: Identifier for the anomaly detection job. It can be a job identifier,
            a group name, or a wildcard expression. If you do not specify one of these
            options, the API returns information for all anomaly detection jobs.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no jobs that match. 2. Contains the _all string
            or no identifiers and there are no matches. 3. Contains wildcard expressions
            and there are only partial matches. The default value is `true`, which returns
            an empty `jobs` array when there are no matches and the subset of results
            when there are partial matches. If this parameter is `false`, the request
            returns a `404` status code when there are no matches or only partial matches.
        :param exclude_generated: Indicates if certain fields should be removed from
            the configuration on retrieval. This allows the configuration to be in an
            acceptable format to be retrieved and then added to another cluster.
        r(   z/_ml/anomaly_detectorsNr"   r	   r   r
   r   r   r   r   r   r   rF   )r   r%   r"   r	   r   r
   r   r   r   r   r   r   r   r   get_jobsX  r   zMlClient.get_jobs)node_idr	   r
   r   master_timeoutr   r$   r   r   c                C   s   |t vrdt| d}nd}i }	|dur||	d< |dur!||	d< |dur)||	d< |dur1||	d< |dur9||	d	< |durA||	d
< ddi}
| jd||	|
dS )a  
        Returns information on how ML is using memory.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-ml-memory.html>`_

        :param node_id: The names of particular nodes in the cluster to target. For example,
            `nodeId1,nodeId2` or `ml:true`
        :param master_timeout: Period to wait for a connection to the master node. If
            no response is received before the timeout expires, the request fails and
            returns an error.
        :param timeout: Period to wait for a response. If no response is received before
            the timeout expires, the request fails and returns an error.
        z/_ml/memory/r   z/_ml/memory/_statsNr	   r
   r   r   r   r$   r   r   r   r   rF   )r   r   r	   r
   r   r   r   r$   r   r   r   r   r   r   get_memory_stats  s(   zMlClient.get_memory_stats)r"   r	   r
   r   r   c                C   s   |t v rtd|t v rtddt| dt| d}i }	|dur'||	d< |dur/||	d< |dur7||	d	< |dur?||	d
< |durG||	d< ddi}
| jd||	|
dS )a  
        Gets stats for anomaly detection job model snapshot upgrades that are in progress.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-job-model-snapshot-upgrade-stats.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: A numerical character string that uniquely identifies the
            model snapshot. You can get information for multiple snapshots by using a
            comma-separated list or a wildcard expression. You can get all snapshots
            by using `_all`, by specifying `*` as the snapshot ID, or by omitting the
            snapshot ID.
        :param allow_no_match: Specifies what to do when the request: - Contains wildcard
            expressions and there are no jobs that match. - Contains the _all string
            or no identifiers and there are no matches. - Contains wildcard expressions
            and there are only partial matches. The default value is true, which returns
            an empty jobs array when there are no matches and the subset of results when
            there are partial matches. If this parameter is false, the request returns
            a 404 status code when there are no matches or only partial matches.
        r'   rU   r(   rV   z/_upgrade/_statsNr"   r	   r
   r   r   r   r   r   r   r   )r   r%   rT   r"   r	   r
   r   r   r   r   r   r   r   r    get_model_snapshot_upgrade_stats  s(   z)MlClient.get_model_snapshot_upgrade_stats)rT   r   rt   r	   r
   r}   r   r   r   r   r   rv   c                C   sH  |t v rtd|t vr|t vrdt| dt| }n|t vr*dt| d}ntdi }i }|dur:||d< |durB||d< |durJ||d	< |durR||d
< |durZ||d< |durb||d< |	durj|	|d< |
durr|
|d< |durz||d< |dur||d< |dur||d< |sd}ddi}|durd|d< | jd||||dS )a&  
        Retrieves information about model snapshots.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-snapshot.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: A numerical character string that uniquely identifies the
            model snapshot. You can get information for multiple snapshots by using a
            comma-separated list or a wildcard expression. You can get all snapshots
            by using `_all`, by specifying `*` as the snapshot ID, or by omitting the
            snapshot ID.
        :param desc: Refer to the description for the `desc` query parameter.
        :param end: Refer to the description for the `end` query parameter.
        :param from_: Skips the specified number of snapshots.
        :param page:
        :param size: Specifies the maximum number of snapshots to obtain.
        :param sort: Refer to the description for the `sort` query parameter.
        :param start: Refer to the description for the `start` query parameter.
        r'   r(   rV   z/model_snapshotsrO   Nr   rt   r	   r
   r|   r   r   r   r   r   rv   r   r   r)   r   r*   r   )r   r%   rT   r   rt   r	   r
   r}   r   r   r   r   r   rv   r   r,   r   r   r   r   r   get_model_snapshots  sN   (
zMlClient.get_model_snapshots)r"   bucket_spanrt   r	   r   r
   r   overall_scorer   rv   top_nr   r   r   c                C   s  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |spd}ddi}|dur|d|d< | jd||||dS )a  
        Retrieves overall bucket results that summarize the bucket results of multiple
        anomaly detection jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-overall-buckets.html>`_

        :param job_id: Identifier for the anomaly detection job. It can be a job identifier,
            a group name, a comma-separated list of jobs or groups, or a wildcard expression.
            You can summarize the bucket results for all anomaly detection jobs by using
            `_all` or by specifying `*` as the `<job_id>`.
        :param allow_no_match: Refer to the description for the `allow_no_match` query
            parameter.
        :param bucket_span: Refer to the description for the `bucket_span` query parameter.
        :param end: Refer to the description for the `end` query parameter.
        :param exclude_interim: Refer to the description for the `exclude_interim` query
            parameter.
        :param overall_score: Refer to the description for the `overall_score` query
            parameter.
        :param start: Refer to the description for the `start` query parameter.
        :param top_n: Refer to the description for the `top_n` query parameter.
        r'   r(   z/results/overall_bucketsNr"   r   rt   r	   r   r
   r   r   r   rv   r   r   r   r)   r   r*   r   )r   r%   r"   r   rt   r	   r   r
   r   r   r   rv   r   r   r,   r   r   r   r   r   get_overall_bucketsC  sF   (
zMlClient.get_overall_buckets)r   rt   r	   r   r
   r}   r   r   r   record_scorer   r   rv   r   c                C   s,  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |sd}ddi}|durd|d< | jd||||dS )a  
        Retrieves anomaly records for an anomaly detection job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-get-record.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param desc: Refer to the description for the `desc` query parameter.
        :param end: Refer to the description for the `end` query parameter.
        :param exclude_interim: Refer to the description for the `exclude_interim` query
            parameter.
        :param from_: Skips the specified number of records.
        :param page:
        :param record_score: Refer to the description for the `record_score` query parameter.
        :param size: Specifies the maximum number of records to obtain.
        :param sort: Refer to the description for the `sort` query parameter.
        :param start: Refer to the description for the `start` query parameter.
        r'   r(   z/results/recordsNr   rt   r	   r   r
   r|   r   r   r   r   r   r   rv   r   r   r)   r   r*   r   )r   r%   r   rt   r	   r   r
   r}   r   r   r   r   r   r   rv   r   r,   r   r   r   r   r   get_records  sN   '
zMlClient.get_records)r   r"   decompress_definitionr	   r   r
   r}   r   includer   r   tagsr   r   zzt.Literal['definition', 'definition_status', 'feature_importance_baseline', 'hyperparameters', 'total_feature_importance']r   c                C   s   |t vrdt| }nd}i }|dur||d< |dur ||d< |dur(||d< |dur0||d< |dur8||d< |dur@||d	< |durH||d
< |	durP|	|d< |
durX|
|d< |dur`||d< |durh||d< ddi}| jd|||dS )a9  
        Retrieves configuration information for a trained inference model.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-trained-models.html>`_

        :param model_id: The unique identifier of the trained model.
        :param allow_no_match: Specifies what to do when the request: - Contains wildcard
            expressions and there are no models that match. - Contains the _all string
            or no identifiers and there are no matches. - Contains wildcard expressions
            and there are only partial matches. If true, it returns an empty array when
            there are no matches and the subset of results when there are partial matches.
        :param decompress_definition: Specifies whether the included model definition
            should be returned as a JSON map (true) or in a custom compressed format
            (false).
        :param exclude_generated: Indicates if certain fields should be removed from
            the configuration on retrieval. This allows the configuration to be in an
            acceptable format to be retrieved and then added to another cluster.
        :param from_: Skips the specified number of models.
        :param include: A comma delimited string of optional fields to include in the
            response body.
        :param size: Specifies the maximum number of models to obtain.
        :param tags: A comma delimited string of tags. A trained model can have many
            tags, or none. When supplied, only trained models that contain all the supplied
            tags are returned.
        r   z/_ml/trained_modelsNr"   r   r	   r   r
   r|   r   r   r   r   r   r   r   r   r   rF   )r   r   r"   r   r	   r   r
   r}   r   r   r   r   r   r   r   r   r   r   r   get_trained_models  s<   1zMlClient.get_trained_models)r   r"   r	   r
   r}   r   r   r   c                C   s   |t vrdt| d}	nd}	i }
|dur||
d< |dur!||
d< |dur)||
d< |dur1||
d< |dur9||
d	< |durA||
d
< |durI||
d< ddi}| jd|	|
|dS )a  
        Retrieves usage information for trained inference models.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-trained-models-stats.html>`_

        :param model_id: The unique identifier of the trained model or a model alias.
            It can be a comma-separated list or a wildcard expression.
        :param allow_no_match: Specifies what to do when the request: - Contains wildcard
            expressions and there are no models that match. - Contains the _all string
            or no identifiers and there are no matches. - Contains wildcard expressions
            and there are only partial matches. If true, it returns an empty array when
            there are no matches and the subset of results when there are partial matches.
        :param from_: Skips the specified number of models.
        :param size: Specifies the maximum number of models to obtain.
        r   r   z/_ml/trained_models/_statsNr"   r	   r
   r|   r   r   r   r   r   r   r   rF   )r   r   r"   r	   r
   r}   r   r   r   r   r   r   r   r   r   get_trained_models_stats/  s,   z!MlClient.get_trained_models_stats)r	   r
   r   inference_configr   r$   docsr   c                C   s   |t v rtd|du rtddt| d}	i }
i }|dur$||
d< |dur,||d< |dur4||d< |dur<||d	< |durD||
d
< |durL||d< |durT||d< ddd}| jd|	|||
dS )a  
        Evaluate a trained model.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/infer-trained-model.html>`_

        :param model_id: The unique identifier of the trained model.
        :param docs: An array of objects to pass to the model for inference. The objects
            should contain a fields matching your configured trained model input. Typically,
            for NLP models, the field name is `text_field`. Currently, for NLP models,
            only a single value is allowed.
        :param inference_config: The inference configuration updates to apply on the
            API call
        :param timeout: Controls the amount of time to wait for inference results.
        r   Nz'Empty value passed for parameter 'docs'r   z/_inferr   r	   r
   r   r   r   r$   r   ra   r   r*   r   )r   r   r   r	   r
   r   r   r   r$   r   r,   r   r   r   r   r   infer_trained_modele  s2   

zMlClient.infer_trained_modelc                C   sb   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< ddi}| j d	|||d
S )z
        Returns defaults and limits used by machine learning.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/get-ml-info.html>`_
        z	/_ml/infoNr	   r
   r   r   r   r   r   r   rb   )r   r	   r
   r   r   r   r   r   r   r   r   info  s   zMlClient.info)r	   r
   r   r   r$   c                C   s   |t v rtddt| d}i }i }	|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||	d	< |	s@d}	d
di}
|	durLd|
d< | jd|||
|	dS )a-  
        Opens one or more anomaly detection jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-open-job.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param timeout: Refer to the description for the `timeout` query parameter.
        r'   r(   z/_openNr	   r
   r   r   r$   r   r   r)   r   r*   r   )r   r%   r	   r
   r   r   r$   r   r   r,   r   r   r   r   open_job  s.   
zMlClient.open_jobeventsc                C   s   |t v rtd|du rtddt| d}i }i }	|dur$||d< |dur,||	d< |dur4||	d< |dur<||	d	< |durD||	d
< ddd}
| jd||	|
|dS )u  
        Posts scheduled events in a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-post-calendar-event.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        :param events: A list of one of more scheduled events. The event’s start and
            end times can be specified as integer milliseconds since the epoch or as
            a string in ISO 8601 format.
        r0   Nz)Empty value passed for parameter 'events'r1   r   r   r	   r
   r   r   r   ra   r   r*   r   )r   r.   r   r	   r
   r   r   r   r,   r   r   r   r   r   post_calendar_events  s*   

zMlClient.post_calendar_eventsdata)Z	body_name)r	   r
   r   r   	reset_endreset_startr   r   c                C   s   |t v rtd|du rtddt| d}	i }
|dur"||
d< |dur*||
d< |dur2||
d< |dur:||
d	< |durB||
d
< |durJ||
d< |}ddd}| jd|	|
||dS )a  
        Sends data to an anomaly detection job for analysis.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-post-data.html>`_

        :param job_id: Identifier for the anomaly detection job. The job must have a
            state of open to receive and process the data.
        :param data:
        :param reset_end: Specifies the end of the bucket resetting range.
        :param reset_start: Specifies the start of the bucket resetting range.
        r'   Nz'Empty value passed for parameter 'data'r(   z/_datar	   r
   r   r   r   r   r   zapplication/x-ndjsonra   r   r*   r   )r   r%   r   r	   r
   r   r   r   r   r   r   r,   r   r   r   r   	post_data	  s2   
zMlClient.post_data)r<   configr	   r
   r   r   r   c                C   s   |t vrdt| d}nd}i }i }	|dur||d< |dur#||	d< |dur+||	d< |dur3||	d< |dur;||	d	< |s?d}d
di}
|durKd|
d< | jd||	|
|dS )u  
        Previews that will be analyzed given a data frame analytics config.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/preview-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job.
        :param config: A data frame analytics config as described in create data frame
            analytics jobs. Note that `id` and `dest` don’t need to be provided in the
            context of this API.
        r>   	/_previewz"/_ml/data_frame/analytics/_previewNr   r	   r
   r   r   r   r   r)   r   r*   rF   )r   r<   r   r	   r
   r   r   r   r,   r   r   r   r   r   preview_data_frame_analyticsH	  s.   
z%MlClient.preview_data_frame_analytics)	r@   datafeed_configrt   r	   r
   r   
job_configr   rv   r   r   c       	         C   s   |t vrdt| d}
nd}
i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d	< |durC||d
< |durK||d< |	durS|	|d< |sWd}ddi}|durcd|d< | jd|
|||dS )a  
        Previews a datafeed.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-preview-datafeed.html>`_

        :param datafeed_id: A numerical character string that uniquely identifies the
            datafeed. This identifier can contain lowercase alphanumeric characters (a-z
            and 0-9), hyphens, and underscores. It must start and end with alphanumeric
            characters. NOTE: If you use this path parameter, you cannot provide datafeed
            or anomaly detection job configuration details in the request body.
        :param datafeed_config: The datafeed definition to preview.
        :param end: The end time when the datafeed preview should stop
        :param job_config: The configuration details for the anomaly detection job that
            is associated with the datafeed. If the `datafeed_config` object does not
            include a `job_id` that references an existing anomaly detection job, you
            must supply this `job_config` object. If you include both a `job_id` and
            a `job_config`, the latter information is used. You cannot specify a `job_config`
            object unless you also supply a `datafeed_config` object.
        :param start: The start time from where the datafeed preview should begin
        rC   r   z/_ml/datafeeds/_previewNr   rt   r	   r
   r   r   r   rv   r   r   r)   r   r*   rF   )r   r@   r   rt   r	   r
   r   r   r   rv   r   r,   r   r   r   r   r   preview_datafeedx	  s:   $
zMlClient.preview_datafeed)rl   r	   r
   r   job_idsr   r   c                C   s   |t v rtddt| }i }	i }
|dur||	d< |dur#||
d< |dur+||
d< |dur3||
d< |dur;||	d< |durC||
d	< |	sGd}	d
di}|	durSd|d< | jd||
||	dS )aW  
        Instantiates a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-put-calendar.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        :param description: A description of the calendar.
        :param job_ids: An array of anomaly detection job identifiers.
        r0   r1   Nrl   r	   r
   r   r   r   r   r   r)   PUTr*   r   )r   r.   rl   r	   r
   r   r   r   r   r,   r   r   r   r   r   put_calendar	  s2   
zMlClient.put_calendarc          
      C   r6   )a  
        Adds an anomaly detection job to a calendar.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-put-calendar-job.html>`_

        :param calendar_id: A string that uniquely identifies a calendar.
        :param job_id: An identifier for the anomaly detection jobs. It can be a job
            identifier, a group name, or a comma-separated list of jobs or groups.
        r0   r'   r1   r9   Nr	   r
   r   r   r   r   r   r   r   r:   r   r   r   put_calendar_job	  r8   zMlClient.put_calendar_jobr   )r!   Zignore_deprecated_options)ri   rk   rl   r	   r
   r   r   rn   ro   r   versionr   c                C   sT  |t v rtd|du rtd|du rtd|du r tddt| }i }i }|dur3||d< |dur;||d< |durC||d	< |durK||d
< |durS||d< |dur[||d< |durc||d< |	durk|	|d< |
durs|
|d< |dur{||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )u  
        Instantiates a data frame analytics job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/put-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. This identifier can contain
            lowercase alphanumeric characters (a-z and 0-9), hyphens, and underscores.
            It must start and end with alphanumeric characters.
        :param analysis: The analysis configuration, which contains the information necessary
            to perform one of the following types of analysis: classification, outlier
            detection, or regression.
        :param dest: The destination configuration.
        :param source: The configuration of how to source the analysis data.
        :param allow_lazy_start: Specifies whether this job can start when there is insufficient
            machine learning node capacity for it to be immediately assigned to a node.
            If set to `false` and a machine learning node with capacity to run the job
            cannot be immediately found, the API returns an error. If set to `true`,
            the API does not return an error; the job waits in the `starting` state until
            sufficient machine learning node capacity is available. This behavior is
            also affected by the cluster-wide `xpack.ml.max_lazy_ml_nodes` setting.
        :param analyzed_fields: Specifies `includes` and/or `excludes` patterns to select
            which fields will be included in the analysis. The patterns specified in
            `excludes` are applied last, therefore `excludes` takes precedence. In other
            words, if the same field is specified in both `includes` and `excludes`,
            then the field will not be included in the analysis. If `analyzed_fields`
            is not set, only the relevant fields will be included. For example, all the
            numeric fields for outlier detection. The supported fields vary for each
            type of analysis. Outlier detection requires numeric or `boolean` data to
            analyze. The algorithms don’t support missing values therefore fields that
            have data types other than numeric or boolean are ignored. Documents where
            included fields contain missing values, null values, or an array are also
            ignored. Therefore the `dest` index may contain documents that don’t have
            an outlier score. Regression supports fields that are numeric, `boolean`,
            `text`, `keyword`, and `ip` data types. It is also tolerant of missing values.
            Fields that are supported are included in the analysis, other fields are
            ignored. Documents where included fields contain an array with two or more
            values are also ignored. Documents in the `dest` index that don’t contain
            a results field are not included in the regression analysis. Classification
            supports fields that are numeric, `boolean`, `text`, `keyword`, and `ip`
            data types. It is also tolerant of missing values. Fields that are supported
            are included in the analysis, other fields are ignored. Documents where included
            fields contain an array with two or more values are also ignored. Documents
            in the `dest` index that don’t contain a results field are not included in
            the classification analysis. Classification analysis can be improved by mapping
            ordinal variable values to a single number. For example, in case of age ranges,
            you can model the values as `0-14 = 0`, `15-24 = 1`, `25-34 = 2`, and so
            on.
        :param description: A description of the job.
        :param headers:
        :param max_num_threads: The maximum number of threads to be used by the analysis.
            Using more threads may decrease the time necessary to complete the analysis
            at the cost of using more CPU. Note that the process may use additional threads
            for operational functionality other than the analysis itself.
        :param model_memory_limit: The approximate maximum amount of memory resources
            that are permitted for analytical processing. If your `elasticsearch.yml`
            file contains an `xpack.ml.max_model_memory_limit` setting, an error occurs
            when you try to create data frame analytics jobs that have `model_memory_limit`
            values greater than that setting.
        :param version:
        r=   Nz+Empty value passed for parameter 'analysis'z'Empty value passed for parameter 'dest'z)Empty value passed for parameter 'source'r>   rj   rm   rp   ri   rk   rl   r	   r
   r   r   rn   ro   r   r   r   ra   r   r*   r   )r   r<   rj   rm   rp   ri   rk   rl   r	   r
   r   r   rn   ro   r   r   r   r,   r   r   r   r   r   put_data_frame_analytics
  sV   S

z!MlClient.put_data_frame_analytics)aggregationsallow_no_indiceschunking_configdelayed_data_check_configr	   expand_wildcardsr
   	frequencyr   r   ignore_throttledignore_unavailableindexesindicesindices_optionsr%   max_empty_searchesr   rd   query_delayruntime_mappingsscript_fieldsscroll_sizer   r   r   r   r   z4t.Literal['all', 'closed', 'hidden', 'none', 'open']r   r   r   r   r   r   r   r   r   r   r   c                C   s  |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< |dur{||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )a  
        Instantiates a datafeed.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-put-datafeed.html>`_

        :param datafeed_id: A numerical character string that uniquely identifies the
            datafeed. This identifier can contain lowercase alphanumeric characters (a-z
            and 0-9), hyphens, and underscores. It must start and end with alphanumeric
            characters.
        :param aggregations: If set, the datafeed performs aggregation searches. Support
            for aggregations is limited and should be used only with low cardinality
            data.
        :param allow_no_indices: If true, wildcard indices expressions that resolve into
            no concrete indices are ignored. This includes the `_all` string or when
            no indices are specified.
        :param chunking_config: Datafeeds might be required to search over long time
            periods, for several months or years. This search is split into time chunks
            in order to ensure the load on Elasticsearch is managed. Chunking configuration
            controls how the size of these time chunks are calculated; it is an advanced
            configuration option.
        :param delayed_data_check_config: Specifies whether the datafeed checks for missing
            data and the size of the window. The datafeed can optionally search over
            indices that have already been read in an effort to determine whether any
            data has subsequently been added to the index. If missing data is found,
            it is a good indication that the `query_delay` is set too low and the data
            is being indexed after the datafeed has passed that moment in time. This
            check runs only on real-time datafeeds.
        :param expand_wildcards: Type of index that wildcard patterns can match. If the
            request can target data streams, this argument determines whether wildcard
            expressions match hidden data streams. Supports comma-separated values.
        :param frequency: The interval at which scheduled queries are made while the
            datafeed runs in real time. The default value is either the bucket span for
            short bucket spans, or, for longer bucket spans, a sensible fraction of the
            bucket span. When `frequency` is shorter than the bucket span, interim results
            for the last (partial) bucket are written then eventually overwritten by
            the full bucket results. If the datafeed uses aggregations, this value must
            be divisible by the interval of the date histogram aggregation.
        :param headers:
        :param ignore_throttled: If true, concrete, expanded, or aliased indices are
            ignored when frozen.
        :param ignore_unavailable: If true, unavailable indices (missing or closed) are
            ignored.
        :param indexes: An array of index names. Wildcards are supported. If any of the
            indices are in remote clusters, the machine learning nodes must have the
            `remote_cluster_client` role.
        :param indices: An array of index names. Wildcards are supported. If any of the
            indices are in remote clusters, the machine learning nodes must have the
            `remote_cluster_client` role.
        :param indices_options: Specifies index expansion options that are used during
            search
        :param job_id: Identifier for the anomaly detection job.
        :param max_empty_searches: If a real-time datafeed has never seen any data (including
            during any initial training period), it automatically stops and closes the
            associated job after this many real-time searches return no documents. In
            other words, it stops after `frequency` times `max_empty_searches` of real-time
            operation. If not set, a datafeed with no end time that sees no data remains
            started until it is explicitly stopped. By default, it is not set.
        :param query: The Elasticsearch query domain-specific language (DSL). This value
            corresponds to the query object in an Elasticsearch search POST body. All
            the options that are supported by Elasticsearch can be used, as this object
            is passed verbatim to Elasticsearch.
        :param query_delay: The number of seconds behind real time that data is queried.
            For example, if data from 10:04 a.m. might not be searchable in Elasticsearch
            until 10:06 a.m., set this property to 120 seconds. The default value is
            randomly selected between `60s` and `120s`. This randomness improves the
            query performance when there are multiple jobs running on the same node.
        :param runtime_mappings: Specifies runtime fields for the datafeed search.
        :param script_fields: Specifies scripts that evaluate custom expressions and
            returns script fields to the datafeed. The detector configuration objects
            in a job can contain functions that use these script fields.
        :param scroll_size: The size parameter that is used in Elasticsearch searches
            when the datafeed does not use aggregations. The maximum value is the value
            of `index.max_result_window`, which is 10,000 by default.
        rB   rC   Nr   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r%   r   r   rd   r   r   r   r   r   ra   r   r*   r   )r   r@   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r   r%   r   r   rd   r   r   r   r   r   r,   r   r   r   r   r   put_datafeed
  sn   q

zMlClient.put_datafeed)rl   r	   r
   r   itemsr   r   c                C   s   |t v rtddt| }i }	i }
|dur||	d< |dur#||
d< |dur+||
d< |dur3||
d< |dur;||	d< |durC||
d	< d
d
d}| jd||
||	dS )a  
        Instantiates a filter.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-put-filter.html>`_

        :param filter_id: A string that uniquely identifies a filter.
        :param description: A description of the filter.
        :param items: The items of the filter. A wildcard `*` can be used at the beginning
            or the end of an item. Up to 10000 items are allowed in each filter.
        rI   rJ   Nrl   r	   r
   r   r   r   r   ra   r   r*   r   )r   rH   rl   r	   r
   r   r   r   r   r,   r   r   r   r   r   
put_filter;  s*   

zMlClient.put_filter)allow_lazy_openanalysis_limitsbackground_persist_intervalcustom_settings)daily_model_snapshot_retention_after_daysr   rl   r	   r
   groupsr   model_plot_configmodel_snapshot_retention_daysr   renormalization_window_daysresults_index_nameresults_retention_daysdata_descriptionr   r   r   r   r   r   r   r   r   r   r   c                C   s  |t v rtd|du rtd|du rtddt| }i }i }|dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |durS||d< |dur[||d< |	durc|	|d< |
durk|
|d< |durs||d< |dur{||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )a  
        Instantiates an anomaly detection job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-put-job.html>`_

        :param job_id: The identifier for the anomaly detection job. This identifier
            can contain lowercase alphanumeric characters (a-z and 0-9), hyphens, and
            underscores. It must start and end with alphanumeric characters.
        :param analysis_config: Specifies how to analyze the data. After you create a
            job, you cannot change the analysis configuration; all the properties are
            informational.
        :param data_description: Defines the format of the input data when you send data
            to the job by using the post data API. Note that when configure a datafeed,
            these properties are automatically set. When data is received via the post
            data API, it is not stored in Elasticsearch. Only the results for anomaly
            detection are retained.
        :param allow_lazy_open: Advanced configuration option. Specifies whether this
            job can open when there is insufficient machine learning node capacity for
            it to be immediately assigned to a node. By default, if a machine learning
            node with capacity to run the job cannot immediately be found, the open anomaly
            detection jobs API returns an error. However, this is also subject to the
            cluster-wide `xpack.ml.max_lazy_ml_nodes` setting. If this option is set
            to true, the open anomaly detection jobs API does not return an error and
            the job waits in the opening state until sufficient machine learning node
            capacity is available.
        :param analysis_limits: Limits can be applied for the resources required to hold
            the mathematical models in memory. These limits are approximate and can be
            set per job. They do not control the memory used by other processes, for
            example the Elasticsearch Java processes.
        :param background_persist_interval: Advanced configuration option. The time between
            each periodic persistence of the model. The default value is a randomized
            value between 3 to 4 hours, which avoids all jobs persisting at exactly the
            same time. The smallest allowed value is 1 hour. For very large models (several
            GB), persistence could take 10-20 minutes, so do not set the `background_persist_interval`
            value too low.
        :param custom_settings: Advanced configuration option. Contains custom meta data
            about the job.
        :param daily_model_snapshot_retention_after_days: Advanced configuration option,
            which affects the automatic removal of old model snapshots for this job.
            It specifies a period of time (in days) after which only the first snapshot
            per day is retained. This period is relative to the timestamp of the most
            recent snapshot for this job. Valid values range from 0 to `model_snapshot_retention_days`.
        :param datafeed_config: Defines a datafeed for the anomaly detection job. If
            Elasticsearch security features are enabled, your datafeed remembers which
            roles the user who created it had at the time of creation and runs the query
            using those same roles. If you provide secondary authorization headers, those
            credentials are used instead.
        :param description: A description of the job.
        :param groups: A list of job groups. A job can belong to no groups or many.
        :param model_plot_config: This advanced configuration option stores model information
            along with the results. It provides a more detailed view into anomaly detection.
            If you enable model plot it can add considerable overhead to the performance
            of the system; it is not feasible for jobs with many entities. Model plot
            provides a simplified and indicative view of the model and its bounds. It
            does not display complex features such as multivariate correlations or multimodal
            data. As such, anomalies may occasionally be reported which cannot be seen
            in the model plot. Model plot config can be configured when the job is created
            or updated later. It must be disabled if performance issues are experienced.
        :param model_snapshot_retention_days: Advanced configuration option, which affects
            the automatic removal of old model snapshots for this job. It specifies the
            maximum period of time (in days) that snapshots are retained. This period
            is relative to the timestamp of the most recent snapshot for this job. By
            default, snapshots ten days older than the newest snapshot are deleted.
        :param renormalization_window_days: Advanced configuration option. The period
            over which adjustments to the score are applied, as new data is seen. The
            default value is the longer of 30 days or 100 bucket spans.
        :param results_index_name: A text string that affects the name of the machine
            learning results index. By default, the job generates an index named `.ml-anomalies-shared`.
        :param results_retention_days: Advanced configuration option. The period of time
            (in days) that results are retained. Age is calculated relative to the timestamp
            of the latest bucket result. If this property has a non-null value, once
            per day at 00:30 (server time), results that are the specified number of
            days older than the latest bucket result are deleted from Elasticsearch.
            The default value is null, which means all results are retained. Annotations
            generated by the system also count as results for retention purposes; they
            are deleted after the same number of days as results. Annotations added by
            users are retained forever.
        r'   Nz2Empty value passed for parameter 'analysis_config'z3Empty value passed for parameter 'data_description'r(   r^   r   r   r   r   r   r   r   rl   r	   r
   r   r   r   r   r   r   r   r   r   ra   r   r*   r   )r   r%   r^   r   r   r   r   r   r   r   rl   r	   r
   r   r   r   r   r   r   r   r   r   r,   r   r   r   r   r   put_jobi  sl   k

zMlClient.put_job)compressed_definitiondefer_definition_decompression
definitionrl   r	   r
   r   r   inputmetadatamodel_size_bytes
model_typeplatform_architecturer   r   r   r   r   r   r   r   r   z3t.Literal['lang_ident', 'pytorch', 'tree_ensemble']r   c                C   s4  |t v rtddt| }i }i }|dur||d< |dur#||d< |dur+||d< |dur3||d< |dur;||d< |durC||d	< |durK||d
< |	durS|	|d< |
dur[|
|d< |durc||d< |durk||d< |durs||d< |dur{||d< |dur||d< |dur||d< ddd}| jd||||dS )a-	  
        Creates an inference trained model.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/put-trained-models.html>`_

        :param model_id: The unique identifier of the trained model.
        :param compressed_definition: The compressed (GZipped and Base64 encoded) inference
            definition of the model. If compressed_definition is specified, then definition
            cannot be specified.
        :param defer_definition_decompression: If set to `true` and a `compressed_definition`
            is provided, the request defers definition decompression and skips relevant
            validations.
        :param definition: The inference definition for the model. If definition is specified,
            then compressed_definition cannot be specified.
        :param description: A human-readable description of the inference trained model.
        :param inference_config: The default configuration for inference. This can be
            either a regression or classification configuration. It must match the underlying
            definition.trained_model's target_type. For pre-packaged models such as ELSER
            the config is not required.
        :param input: The input field names for the model definition.
        :param metadata: An object map that contains metadata about the model.
        :param model_size_bytes: The estimated memory usage in bytes to keep the trained
            model in memory. This property is supported only if defer_definition_decompression
            is true or the model definition is not supplied.
        :param model_type: The model type.
        :param platform_architecture: The platform architecture (if applicable) of the
            trained mode. If the model only works on one platform, because it is heavily
            optimized for a particular processor architecture and OS combination, then
            this field specifies which. The format of the string must match the platform
            identifiers used by Elasticsearch, so one of, `linux-x86_64`, `linux-aarch64`,
            `darwin-x86_64`, `darwin-aarch64`, or `windows-x86_64`. For portable models
            (those that work independent of processor architecture or OS features), leave
            this field unset.
        :param tags: An array of tags to organize the model.
        r   r   Nr   r   r   rl   r	   r
   r   r   r   r   r   r   r   r   r   r   ra   r   r*   r   )r   r   r   r   r   rl   r	   r
   r   r   r   r   r   r   r   r   r   r   r,   r   r   r   r   r   put_trained_model
  sN   <

zMlClient.put_trained_model)r	   r
   r   r   reassignr   c                C   s   |t v rtd|t v rtddt| dt| }i }	|dur&||	d< |dur.||	d< |dur6||	d< |dur>||	d	< |durF||	d
< ddi}
| jd||	|
dS )a  
        Creates a new model alias (or reassigns an existing one) to refer to the trained
        model

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/put-trained-models-aliases.html>`_

        :param model_id: The identifier for the trained model that the alias refers to.
        :param model_alias: The alias to create or update. This value cannot end in numbers.
        :param reassign: Specifies whether the alias gets reassigned to the specified
            trained model if it is already assigned to a different model. If the alias
            is already assigned and this parameter is false, the API returns an error.
        r   r[   r   r\   Nr	   r
   r   r   r   r   r   r   r   r   )r   r   rZ   r	   r
   r   r   r   r   r   r   r   r   r   put_trained_model_aliasn  s(   z MlClient.put_trained_model_aliasparttotal_definition_lengthtotal_partsc       	         C   s   |t v rtd|t v rtd|du rtd|du r td|du r(tddt| dt| }
i }i }|dur@||d	< |durH||d
< |durP||d< |durX||d< |dur`||d< |durh||d< |	durp|	|d< ddd}| jd|
|||dS )aN  
        Creates part of a trained model definition

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/put-trained-model-definition-part.html>`_

        :param model_id: The unique identifier of the trained model.
        :param part: The definition part number. When the definition is loaded for inference
            the definition parts are streamed in the order of their part number. The
            first part must be `0` and the final part must be `total_parts - 1`.
        :param definition: The definition part for the model. Must be a base64 encoded
            string.
        :param total_definition_length: The total uncompressed definition length in bytes.
            Not base64 encoded.
        :param total_parts: The total number of parts that will be uploaded. Must be
            greater than 0.
        r   z'Empty value passed for parameter 'part'Nz-Empty value passed for parameter 'definition'z:Empty value passed for parameter 'total_definition_length'z.Empty value passed for parameter 'total_parts'r   z/definition/r   r   r   r	   r
   r   r   r   ra   r   r*   r   )r   r   r   r   r   r   r	   r
   r   r   r   r,   r   r   r   r   r   !put_trained_model_definition_part  sB    

z*MlClient.put_trained_model_definition_part)r	   r
   r   mergesr   scores
vocabularyr   r   c                C   s   |t v rtd|du rtddt| d}	i }
i }|dur$||
d< |dur,||d< |dur4||d< |dur<||d	< |durD||
d
< |durL||d< |durT||
d< ddd}| jd|	|||
dS )a  
        Creates a trained model vocabulary

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/put-trained-model-vocabulary.html>`_

        :param model_id: The unique identifier of the trained model.
        :param vocabulary: The model vocabulary, which must not be empty.
        :param merges: The optional model merges if required by the tokenizer.
        :param scores: The optional vocabulary value scores if required by the tokenizer.
        r   Nz-Empty value passed for parameter 'vocabulary'r   z/vocabularyr   r	   r
   r   r   r   r   r   ra   r   r*   r   )r   r   r   r	   r
   r   r   r   r   r   r,   r   r   r   r   r   put_trained_model_vocabulary  s2   

z%MlClient.put_trained_model_vocabulary)rQ   r	   r
   r   r   rR   c                C      |t v rtddt| d}i }	|dur||	d< |dur"||	d< |dur*||	d< |dur2||	d< |dur:||	d	< |durB||	d
< ddi}
| jd||	|
dS )a  
        Resets an existing anomaly detection job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-reset-job.html>`_

        :param job_id: The ID of the job to reset.
        :param delete_user_annotations: Specifies whether annotations that have been
            added by the user should be deleted along with any auto-generated annotations
            when the job is reset.
        :param wait_for_completion: Should this request wait until the operation has
            completed before returning.
        r'   r(   z/_resetNrQ   r	   r
   r   r   rR   r   r   r   r   r   )r   r%   rQ   r	   r
   r   r   rR   r   r   r   r   r   r   	reset_job  s(   zMlClient.reset_job)delete_intervening_resultsr	   r
   r   r   r   c                C   s   |t v rtd|t v rtddt| dt| d}i }	i }
|dur)||	d< |dur1||
d< |dur9||
d	< |durA||
d
< |durI||
d< |	sMd}	ddi}|	durYd|d< | jd||
||	dS )a;  
        Reverts to a specific snapshot.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-revert-snapshot.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: You can specify `empty` as the <snapshot_id>. Reverting to
            the empty snapshot means the anomaly detection job starts learning a new
            model from scratch when it is started.
        :param delete_intervening_results: Refer to the description for the `delete_intervening_results`
            query parameter.
        r'   rU   r(   rV   z/_revertNr   r	   r
   r   r   r   r   r)   r   r*   r   )r   r%   rT   r   r	   r
   r   r   r   r,   r   r   r   r   r   revert_model_snapshot=  s2   
zMlClient.revert_model_snapshot)enabledr	   r
   r   r   r$   r   c          
      C   s   d}i }|dur||d< |dur||d< |dur||d< |dur$||d< |dur,||d< |dur4||d< d	d
i}	| j d|||	dS )a  
        Sets a cluster wide upgrade_mode setting that prepares machine learning indices
        for an upgrade.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-set-upgrade-mode.html>`_

        :param enabled: When `true`, it enables `upgrade_mode` which temporarily halts
            all job and datafeed tasks and prohibits new job and datafeed tasks from
            starting.
        :param timeout: The time to wait for the request to be completed.
        z/_ml/set_upgrade_modeNr   r	   r
   r   r   r$   r   r   r   r   rb   )
r   r   r	   r
   r   r   r$   r   r   r   r   r   r   set_upgrade_modeq  s$   zMlClient.set_upgrade_modec          
      C   s   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< |dur:||d	< d
di}	| jd|||	dS )a  
        Starts a data frame analytics job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/start-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. This identifier can contain
            lowercase alphanumeric characters (a-z and 0-9), hyphens, and underscores.
            It must start and end with alphanumeric characters.
        :param timeout: Controls the amount of time to wait until the data frame analytics
            job starts.
        r=   r>   /_startNr	   r
   r   r   r$   r   r   r   r   r   )
r   r<   r	   r
   r   r   r$   r   r   r   r   r   r   start_data_frame_analytics  s$   z#MlClient.start_data_frame_analytics)rt   r	   r
   r   r   rv   r$   c                C   s   |t v rtddt| d}	i }
i }|dur||
d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||
d
< |durL||
d< |
sPd}
ddi}|
dur\d|d< | jd|	|||
dS )a  
        Starts one or more datafeeds.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-start-datafeed.html>`_

        :param datafeed_id: A numerical character string that uniquely identifies the
            datafeed. This identifier can contain lowercase alphanumeric characters (a-z
            and 0-9), hyphens, and underscores. It must start and end with alphanumeric
            characters.
        :param end: Refer to the description for the `end` query parameter.
        :param start: Refer to the description for the `start` query parameter.
        :param timeout: Refer to the description for the `timeout` query parameter.
        rB   rC   r   Nrt   r	   r
   r   r   rv   r$   r   r   r)   r   r*   r   )r   r@   rt   r	   r
   r   r   rv   r$   r   r,   r   r   r   r   r   start_datafeed  s6   
zMlClient.start_datafeed)
cache_sizedeployment_idr	   r
   r   number_of_allocationsr   priorityqueue_capacitythreads_per_allocationr$   wait_forr  r  r  r  zt.Literal['low', 'normal']r  r  r  z3t.Literal['fully_allocated', 'started', 'starting']c                C   s   |t v rtddt| d}i }|dur||d< |dur"||d< |dur*||d< |dur2||d< |dur:||d	< |durB||d
< |durJ||d< |	durR|	|d< |
durZ|
|d< |durb||d< |durj||d< |durr||d< ddi}| jd|||dS )a@  
        Start a trained model deployment.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/start-trained-model-deployment.html>`_

        :param model_id: The unique identifier of the trained model. Currently, only
            PyTorch models are supported.
        :param cache_size: The inference cache size (in memory outside the JVM heap)
            per node for the model. The default value is the same size as the `model_size_bytes`.
            To disable the cache, `0b` can be provided.
        :param deployment_id: A unique identifier for the deployment of the model.
        :param number_of_allocations: The number of model allocations on each node where
            the model is deployed. All allocations on a node share the same copy of the
            model in memory but use a separate set of threads to evaluate the model.
            Increasing this value generally increases the throughput. If this setting
            is greater than the number of hardware threads it will automatically be changed
            to a value less than the number of hardware threads.
        :param priority: The deployment priority.
        :param queue_capacity: Specifies the number of inference requests that are allowed
            in the queue. After the number of requests exceeds this value, new requests
            are rejected with a 429 error.
        :param threads_per_allocation: Sets the number of threads used by each model
            allocation during inference. This generally increases the inference speed.
            The inference process is a compute-bound process; any number greater than
            the number of available hardware threads on the machine does not increase
            the inference speed. If this setting is greater than the number of hardware
            threads it will automatically be changed to a value less than the number
            of hardware threads.
        :param timeout: Specifies the amount of time to wait for the model to deploy.
        :param wait_for: Specifies the allocation status to wait for before returning.
        r   r   z/deployment/_startNr  r  r	   r
   r   r  r   r  r  r  r$   r  r   r   r   r   r   )r   r   r  r  r	   r
   r   r  r   r  r  r  r$   r  r   r   r   r   r   r   start_trained_model_deployment  s@   3z'MlClient.start_trained_model_deploymentc                C   s   |t v rtddt| d}	i }
|dur||
d< |dur"||
d< |dur*||
d< |dur2||
d< |dur:||
d	< |durB||
d
< |durJ||
d< ddi}| jd|	|
|dS )a  
        Stops one or more data frame analytics jobs.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/stop-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. This identifier can contain
            lowercase alphanumeric characters (a-z and 0-9), hyphens, and underscores.
            It must start and end with alphanumeric characters.
        :param allow_no_match: Specifies what to do when the request: 1. Contains wildcard
            expressions and there are no data frame analytics jobs that match. 2. Contains
            the _all string or no identifiers and there are no matches. 3. Contains wildcard
            expressions and there are only partial matches. The default value is true,
            which returns an empty data_frame_analytics array when there are no matches
            and the subset of results when there are partial matches. If this parameter
            is false, the request returns a 404 status code when there are no matches
            or only partial matches.
        :param force: If true, the data frame analytics job is stopped forcefully.
        :param timeout: Controls the amount of time to wait until the data frame analytics
            job stops. Defaults to 20 seconds.
        r=   r>   /_stopNr"   r	   r
   r#   r   r   r$   r   r   r   r   r   )r   r<   r"   r	   r
   r#   r   r   r$   r   r   r   r   r   r   stop_data_frame_analyticsO  s,   !z"MlClient.stop_data_frame_analyticsc                C   r&   )a  
        Stops one or more datafeeds.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-stop-datafeed.html>`_

        :param datafeed_id: Identifier for the datafeed. You can stop multiple datafeeds
            in a single API request by using a comma-separated list of datafeeds or a
            wildcard expression. You can close all datafeeds by using `_all` or by specifying
            `*` as the identifier.
        :param allow_no_match: Refer to the description for the `allow_no_match` query
            parameter.
        :param force: Refer to the description for the `force` query parameter.
        :param timeout: Refer to the description for the `timeout` query parameter.
        rB   rC   r	  Nr"   r	   r
   r#   r   r   r$   r   r   r)   r   r*   r   )r   r@   r"   r	   r
   r#   r   r   r$   r   r,   r   r   r   r   r   stop_datafeed  s6   
zMlClient.stop_datafeed)r"   r	   r
   r#   r   r   c                C   r   )a  
        Stop a trained model deployment.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/stop-trained-model-deployment.html>`_

        :param model_id: The unique identifier of the trained model.
        :param allow_no_match: Specifies what to do when the request: contains wildcard
            expressions and there are no deployments that match; contains the `_all`
            string or no identifiers and there are no matches; or contains wildcard expressions
            and there are only partial matches. By default, it returns an empty array
            when there are no matches and the subset of results when there are partial
            matches. If `false`, the request returns a 404 status code when there are
            no matches or only partial matches.
        :param force: Forcefully stops the deployment, even if it is used by ingest pipelines.
            You can't use these pipelines until you restart the model deployment.
        r   r   z/deployment/_stopNr"   r	   r
   r#   r   r   r   r   r   r   r   )r   r   r"   r	   r
   r#   r   r   r   r   r   r   r   r   stop_trained_model_deployment  s(   z&MlClient.stop_trained_model_deployment)ri   rl   r	   r
   r   rn   ro   r   c       	         C   s   |t v rtddt| d}
i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< ddd}| jd|
|||dS )aw  
        Updates certain properties of a data frame analytics job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/update-dfanalytics.html>`_

        :param id: Identifier for the data frame analytics job. This identifier can contain
            lowercase alphanumeric characters (a-z and 0-9), hyphens, and underscores.
            It must start and end with alphanumeric characters.
        :param allow_lazy_start: Specifies whether this job can start when there is insufficient
            machine learning node capacity for it to be immediately assigned to a node.
        :param description: A description of the job.
        :param max_num_threads: The maximum number of threads to be used by the analysis.
            Using more threads may decrease the time necessary to complete the analysis
            at the cost of using more CPU. Note that the process may use additional threads
            for operational functionality other than the analysis itself.
        :param model_memory_limit: The approximate maximum amount of memory resources
            that are permitted for analytical processing. If your `elasticsearch.yml`
            file contains an `xpack.ml.max_model_memory_limit` setting, an error occurs
            when you try to create data frame analytics jobs that have `model_memory_limit`
            values greater than that setting.
        r=   r>   /_updateNri   rl   r	   r
   r   rn   ro   r   r   ra   r   r*   r   )r   r<   ri   rl   r	   r
   r   rn   ro   r   r   r,   r   r   r   r   r   update_data_frame_analytics  s2   %

z$MlClient.update_data_frame_analytics)r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r%   r   r   rd   r   r   r   r   c                C   s  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )a{  
        Updates certain properties of a datafeed.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-update-datafeed.html>`_

        :param datafeed_id: A numerical character string that uniquely identifies the
            datafeed. This identifier can contain lowercase alphanumeric characters (a-z
            and 0-9), hyphens, and underscores. It must start and end with alphanumeric
            characters.
        :param aggregations: If set, the datafeed performs aggregation searches. Support
            for aggregations is limited and should be used only with low cardinality
            data.
        :param allow_no_indices: If `true`, wildcard indices expressions that resolve
            into no concrete indices are ignored. This includes the `_all` string or
            when no indices are specified.
        :param chunking_config: Datafeeds might search over long time periods, for several
            months or years. This search is split into time chunks in order to ensure
            the load on Elasticsearch is managed. Chunking configuration controls how
            the size of these time chunks are calculated; it is an advanced configuration
            option.
        :param delayed_data_check_config: Specifies whether the datafeed checks for missing
            data and the size of the window. The datafeed can optionally search over
            indices that have already been read in an effort to determine whether any
            data has subsequently been added to the index. If missing data is found,
            it is a good indication that the `query_delay` is set too low and the data
            is being indexed after the datafeed has passed that moment in time. This
            check runs only on real-time datafeeds.
        :param expand_wildcards: Type of index that wildcard patterns can match. If the
            request can target data streams, this argument determines whether wildcard
            expressions match hidden data streams. Supports comma-separated values. Valid
            values are: * `all`: Match any data stream or index, including hidden ones.
            * `closed`: Match closed, non-hidden indices. Also matches any non-hidden
            data stream. Data streams cannot be closed. * `hidden`: Match hidden data
            streams and hidden indices. Must be combined with `open`, `closed`, or both.
            * `none`: Wildcard patterns are not accepted. * `open`: Match open, non-hidden
            indices. Also matches any non-hidden data stream.
        :param frequency: The interval at which scheduled queries are made while the
            datafeed runs in real time. The default value is either the bucket span for
            short bucket spans, or, for longer bucket spans, a sensible fraction of the
            bucket span. When `frequency` is shorter than the bucket span, interim results
            for the last (partial) bucket are written then eventually overwritten by
            the full bucket results. If the datafeed uses aggregations, this value must
            be divisible by the interval of the date histogram aggregation.
        :param ignore_throttled: If `true`, concrete, expanded or aliased indices are
            ignored when frozen.
        :param ignore_unavailable: If `true`, unavailable indices (missing or closed)
            are ignored.
        :param indexes: An array of index names. Wildcards are supported. If any of the
            indices are in remote clusters, the machine learning nodes must have the
            `remote_cluster_client` role.
        :param indices: An array of index names. Wildcards are supported. If any of the
            indices are in remote clusters, the machine learning nodes must have the
            `remote_cluster_client` role.
        :param indices_options: Specifies index expansion options that are used during
            search.
        :param job_id:
        :param max_empty_searches: If a real-time datafeed has never seen any data (including
            during any initial training period), it automatically stops and closes the
            associated job after this many real-time searches return no documents. In
            other words, it stops after `frequency` times `max_empty_searches` of real-time
            operation. If not set, a datafeed with no end time that sees no data remains
            started until it is explicitly stopped. By default, it is not set.
        :param query: The Elasticsearch query domain-specific language (DSL). This value
            corresponds to the query object in an Elasticsearch search POST body. All
            the options that are supported by Elasticsearch can be used, as this object
            is passed verbatim to Elasticsearch. Note that if you change the query, the
            analyzed data is also changed. Therefore, the time required to learn might
            be long and the understandability of the results is unpredictable. If you
            want to make significant changes to the source data, it is recommended that
            you clone the job and datafeed and make the amendments in the clone. Let
            both run in parallel and close one when you are satisfied with the results
            of the job.
        :param query_delay: The number of seconds behind real time that data is queried.
            For example, if data from 10:04 a.m. might not be searchable in Elasticsearch
            until 10:06 a.m., set this property to 120 seconds. The default value is
            randomly selected between `60s` and `120s`. This randomness improves the
            query performance when there are multiple jobs running on the same node.
        :param runtime_mappings: Specifies runtime fields for the datafeed search.
        :param script_fields: Specifies scripts that evaluate custom expressions and
            returns script fields to the datafeed. The detector configuration objects
            in a job can contain functions that use these script fields.
        :param scroll_size: The size parameter that is used in Elasticsearch searches
            when the datafeed does not use aggregations. The maximum value is the value
            of `index.max_result_window`.
        rB   rC   r  Nr   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r%   r   r   rd   r   r   r   r   r   ra   r   r*   r   )r   r@   r   r   r   r   r	   r   r
   r   r   r   r   r   r   r   r%   r   r   rd   r   r   r   r   r   r,   r   r   r   r   r   update_datafeed0  sj   z

zMlClient.update_datafeed)	add_itemsrl   r	   r
   r   r   remove_itemsr  r  c                C   s   |t v rtddt| d}	i }
i }|dur||
d< |dur$||
d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||
d< ddd}| jd|	|||
dS )a  
        Updates the description of a filter, adds items, or removes items.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-update-filter.html>`_

        :param filter_id: A string that uniquely identifies a filter.
        :param add_items: The items to add to the filter.
        :param description: A description for the filter.
        :param remove_items: The items to remove from the filter.
        rI   rJ   r  Nr  rl   r	   r
   r   r   r  r   ra   r   r*   r   )r   rH   r  rl   r	   r
   r   r   r  r   r,   r   r   r   r   r   update_filter  s.   

zMlClient.update_filter)r   r   r   categorization_filtersr   r   rl   	detectorsr	   r
   r   r   r   model_prune_windowr   per_partition_categorizationr   r   r   r  r  r  r  c                C   sv  |t v rtddt| d}i }i }|dur||d< |dur$||d< |dur,||d< |dur4||d< |dur<||d	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< |durl||d< |durt||d< |dur|||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< |dur||d< ddd}| jd||||dS )a7  
        Updates certain properties of an anomaly detection job.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-update-job.html>`_

        :param job_id: Identifier for the job.
        :param allow_lazy_open: Advanced configuration option. Specifies whether this
            job can open when there is insufficient machine learning node capacity for
            it to be immediately assigned to a node. If `false` and a machine learning
            node with capacity to run the job cannot immediately be found, the open anomaly
            detection jobs API returns an error. However, this is also subject to the
            cluster-wide `xpack.ml.max_lazy_ml_nodes` setting. If this option is set
            to `true`, the open anomaly detection jobs API does not return an error and
            the job waits in the opening state until sufficient machine learning node
            capacity is available.
        :param analysis_limits:
        :param background_persist_interval: Advanced configuration option. The time between
            each periodic persistence of the model. The default value is a randomized
            value between 3 to 4 hours, which avoids all jobs persisting at exactly the
            same time. The smallest allowed value is 1 hour. For very large models (several
            GB), persistence could take 10-20 minutes, so do not set the value too low.
            If the job is open when you make the update, you must stop the datafeed,
            close the job, then reopen the job and restart the datafeed for the changes
            to take effect.
        :param categorization_filters:
        :param custom_settings: Advanced configuration option. Contains custom meta data
            about the job. For example, it can contain custom URL information as shown
            in Adding custom URLs to machine learning results.
        :param daily_model_snapshot_retention_after_days: Advanced configuration option,
            which affects the automatic removal of old model snapshots for this job.
            It specifies a period of time (in days) after which only the first snapshot
            per day is retained. This period is relative to the timestamp of the most
            recent snapshot for this job. Valid values range from 0 to `model_snapshot_retention_days`.
            For jobs created before version 7.8.0, the default value matches `model_snapshot_retention_days`.
        :param description: A description of the job.
        :param detectors: An array of detector update objects.
        :param groups: A list of job groups. A job can belong to no groups or many.
        :param model_plot_config:
        :param model_prune_window:
        :param model_snapshot_retention_days: Advanced configuration option, which affects
            the automatic removal of old model snapshots for this job. It specifies the
            maximum period of time (in days) that snapshots are retained. This period
            is relative to the timestamp of the most recent snapshot for this job.
        :param per_partition_categorization: Settings related to how categorization interacts
            with partition fields.
        :param renormalization_window_days: Advanced configuration option. The period
            over which adjustments to the score are applied, as new data is seen.
        :param results_retention_days: Advanced configuration option. The period of time
            (in days) that results are retained. Age is calculated relative to the timestamp
            of the latest bucket result. If this property has a non-null value, once
            per day at 00:30 (server time), results that are the specified number of
            days older than the latest bucket result are deleted from Elasticsearch.
            The default value is null, which means all results are retained.
        r'   r(   r  Nr   r   r   r  r   r   rl   r  r	   r
   r   r   r   r  r   r  r   r   r   r   ra   r   r*   r   )r   r%   r   r   r   r  r   r   rl   r  r	   r
   r   r   r   r  r   r  r   r   r   r   r,   r   r   r   r   r   
update_job  sd   U

zMlClient.update_job)rl   r	   r
   r   r   retainr  c                C   s   |t v rtd|t v rtddt| dt| d}	i }
i }|dur)||
d< |dur1||d< |dur9||d	< |durA||d
< |durI||d< |durQ||
d< ddd}| jd|	|||
dS )aN  
        Updates certain properties of a snapshot.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-update-snapshot.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: Identifier for the model snapshot.
        :param description: A description of the model snapshot.
        :param retain: If `true`, this snapshot will not be deleted during automatic
            cleanup of snapshots older than `model_snapshot_retention_days`. However,
            this snapshot will be deleted when the job is deleted.
        r'   rU   r(   rV   r  Nrl   r	   r
   r   r   r  r   ra   r   r*   r   )r   r%   rT   rl   r	   r
   r   r   r  r   r,   r   r   r   r   r   update_model_snapshot  s.   

zMlClient.update_model_snapshot)r	   r
   r   r   r$   rR   c                C   s   |t v rtd|t v rtddt| dt| d}	i }
|dur'||
d< |dur/||
d< |dur7||
d	< |dur?||
d
< |durG||
d< |durO||
d< ddi}| jd|	|
|dS )u  
        Upgrades a given job snapshot to the current major version.

        `<https://www.elastic.co/guide/en/elasticsearch/reference/8.11/ml-upgrade-job-model-snapshot.html>`_

        :param job_id: Identifier for the anomaly detection job.
        :param snapshot_id: A numerical character string that uniquely identifies the
            model snapshot.
        :param timeout: Controls the time to wait for the request to complete.
        :param wait_for_completion: When true, the API won’t respond until the upgrade
            is complete. Otherwise, it responds as soon as the upgrade task is assigned
            to a node.
        r'   rU   r(   rV   z	/_upgradeNr	   r
   r   r   r$   rR   r   r   r   r   r   )r   r%   rT   r	   r
   r   r   r$   rR   r   r   r   r   r   r   upgrade_job_snapshot  s,   zMlClient.upgrade_job_snapshot)r^   r   r   rl   r	   r
   r   r%   
model_plotmodel_snapshot_idr   r   r   r  r  c                C   s   d}i }i }|dur||d< |dur||d< |dur||d< |dur&||d< |dur.||d< |dur6||d< |dur>||d	< |durF||d
< |	durN|	|d< |
durV|
|d< |dur^||d< |durf||d< |durn||d< ddd}| j d||||dS )a  
        Validates an anomaly detection job.

        `<https://www.elastic.co/guide/en/machine-learning/8.11/ml-jobs.html>`_

        :param analysis_config:
        :param analysis_limits:
        :param data_description:
        :param description:
        :param job_id:
        :param model_plot:
        :param model_snapshot_id:
        :param model_snapshot_retention_days:
        :param results_index_name:
        z /_ml/anomaly_detectors/_validateNr^   r   r   rl   r	   r
   r   r%   r  r  r   r   r   r   ra   r   r*   rb   )r   r^   r   r   rl   r	   r
   r   r%   r  r  r   r   r   r   r,   r   r   r   r   r   validate  sB   #

zMlClient.validatedetectorc          
      C   sz   |du rt dd}i }|dur||d< |dur||d< |dur$||d< |dur,||d< |}ddd	}	| jd
|||	|dS )z
        Validates an anomaly detection detector.

        `<https://www.elastic.co/guide/en/machine-learning/8.11/ml-jobs.html>`_

        :param detector:
        Nz+Empty value passed for parameter 'detector'z)/_ml/anomaly_detectors/_validate/detectorr	   r
   r   r   r   ra   r   r*   rg   )
r   r  r	   r
   r   r   r   r   r,   r   r   r   r   validate_detectorA  s"   

zMlClient.validate_detector)W__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr    r-   r3   r7   r;   r?   rD   floatrG   rK   rP   rS   rW   rY   r]   Mappingintrc   rh   rq   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r      s   !	
8!	&	&	
*	)	
2!	
7	
1	%	'	%	
5	
/	
Y	
:	
4	
X	
9	
8	
A	
=	
;	.	
4	
*	
P	/	
4
0	
3	
M	
I	
K	
N	
3	
4	*	*
	
2	-	
@	
.	&	
"{	" !" &	
+	
 	

a	
,	
?	
0	
,	
1
	(	(	
5	
S	
7	
6	
0	
<	 ! .	
.	
 	
0	
0	
Br   )typingr$  Zelastic_transportr   _baser   utilsr   r   r   r   r   r   r   r   <module>   s
   