o
    gZhG                     @   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                    @   sx  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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Ze 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
ej fddZe ddddd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hddddddddddededejeejf dedededeje dejejeej	e f  dejejeejeej	e f f  deje deje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d d!Zedd"ddddddddddd#
dejeej	e f d$ejejeejeejf f  d%ejejeejeejf 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 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 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jddef  d/eje de
ej fd0d1ZdS )2RollupClientN)error_tracefilter_pathhumanprettyidr	   r
   r   r   returnc          	      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d	i}| jd
|||dS )z
        Deletes an existing rollup job.

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

        :param id: Identifier for the job.
        %Empty value passed for parameter 'id'/_rollup/job/Nr	   r
   r   r   acceptapplication/jsonDELETEparamsheadersr   
ValueErrorr   perform_request	selfr   r	   r
   r   r   _RollupClient__path_RollupClient__query_RollupClient__headers r   X/var/www/html/lang_env/lib/python3.10/site-packages/elasticsearch/_sync/client/rollup.py
delete_job   s    zRollupClient.delete_job)r   r	   r
   r   r   c          	      C   z   |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d	i}| jd
|||dS )a+  
        Retrieves the configuration, stats, and status of rollup jobs.

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

        :param id: Identifier for the rollup job. If it is `_all` or omitted, the API
            returns all rollup jobs.
        r   z/_rollup/jobNr	   r
   r   r   r   r   GETr   r   r   r   r   r   r   r    get_jobs=   s    zRollupClient.get_jobsc          	      C   r"   )a  
        Returns the capabilities of any rollup jobs that have been configured for a specific
        index or index pattern.

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

        :param id: Index, indices or index-pattern to return rollup capabilities for.
            `_all` may be used to fetch rollup capabilities from all jobs.
        z/_rollup/data//_rollup/dataNr	   r
   r   r   r   r   r#   r   r$   r   r   r   r    get_rollup_capsa   s    zRollupClient.get_rollup_capsindexc          	      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	d
i}| jd|||dS )a}  
        Returns the rollup capabilities of all jobs inside of a rollup index (e.g. the
        index where rollup data is stored).

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

        :param index: Data stream or index to check for rollup capabilities. Wildcard
            (`*`) expressions are supported.
        (Empty value passed for parameter 'index'/r&   Nr	   r
   r   r   r   r   r#   r   r   )	r   r(   r	   r
   r   r   r   r   r   r   r   r    get_rollup_index_caps   s    z"RollupClient.get_rollup_index_capsTr   )body_fieldsZignore_deprecated_options)r	   r
   r   r   metricsr   timeoutcrongroupsindex_pattern	page_sizerollup_indexr.   r/   zt.Literal[-1]zt.Literal[0]c                C   sT  |t v rtd|du rtd|du rtd|du r td|du r(td|du r0tddt| }i }i }|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 )uK  
        Creates a rollup job.

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

        :param id: Identifier for the rollup job. This can be any alphanumeric string
            and uniquely identifies the data that is associated with the rollup job.
            The ID is persistent; it is stored with the rolled up data. If you create
            a job, let it run for a while, then delete the job, the data that the job
            rolled up is still be associated with this job ID. You cannot create a new
            job with the same ID since that could lead to problems with mismatched job
            configurations.
        :param cron: A cron string which defines the intervals when the rollup job should
            be executed. When the interval triggers, the indexer attempts to rollup the
            data in the index pattern. The cron pattern is unrelated to the time interval
            of the data being rolled up. For example, you may wish to create hourly rollups
            of your document but to only run the indexer on a daily basis at midnight,
            as defined by the cron. The cron pattern is defined just like a Watcher cron
            schedule.
        :param groups: Defines the grouping fields and aggregations that are defined
            for this rollup job. These fields will then be available later for aggregating
            into buckets. These aggs and fields can be used in any combination. Think
            of the groups configuration as defining a set of tools that can later be
            used in aggregations to partition the data. Unlike raw data, we have to think
            ahead to which fields and aggregations might be used. Rollups provide enough
            flexibility that you simply need to determine which fields are needed, not
            in what order they are needed.
        :param index_pattern: The index or index pattern to roll up. Supports wildcard-style
            patterns (`logstash-*`). The job attempts to rollup the entire index or index-pattern.
        :param page_size: The number of bucket results that are processed on each iteration
            of the rollup indexer. A larger value tends to execute faster, but requires
            more memory during processing. This value has no effect on how the data is
            rolled up; it is merely used for tweaking the speed or memory cost of the
            indexer.
        :param rollup_index: The index that contains the rollup results. The index can
            be shared with other rollup jobs. The data is stored so that it doesn’t interfere
            with unrelated jobs.
        :param headers:
        :param metrics: Defines the metrics to collect for each grouping tuple. By default,
            only the doc_counts are collected for each group. To make rollup useful,
            you will often add metrics like averages, mins, maxes, etc. Metrics are defined
            on a per-field basis and for each field you configure which metric should
            be collected.
        :param timeout: Time to wait for the request to complete.
        r   Nz'Empty value passed for parameter 'cron'z)Empty value passed for parameter 'groups'z0Empty value passed for parameter 'index_pattern'z,Empty value passed for parameter 'page_size'z/Empty value passed for parameter 'rollup_index'r   r0   r1   r2   r3   r4   r	   r
   r   r   r.   r   r/   r   r   zcontent-typePUTr   r   bodyr   )r   r   r0   r1   r2   r3   r4   r	   r
   r   r   r.   r   r/   r   _RollupClient__bodyr   r   r   r   r    put_job   sV   B

zRollupClient.put_job)r-   )
aggregationsaggsr	   r
   r   r   queryrest_total_hits_as_intsize
typed_keysr;   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	< |durD||d
< |durL||d< |	durT|	|d< |
dur\|
|d< |durd||d< ddd}| jd||||dS )a  
        Enables searching rolled-up data using the standard query DSL.

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

        :param index: Enables searching rolled-up data using the standard Query DSL.
        :param aggregations: Specifies aggregations.
        :param aggs: Specifies aggregations.
        :param query: Specifies a DSL query.
        :param rest_total_hits_as_int: Indicates whether hits.total should be rendered
            as an integer or an object in the rest search response
        :param size: Must be zero if set, as rollups work on pre-aggregated data.
        :param typed_keys: Specify whether aggregation and suggester names should be
            prefixed by their respective types in the response
        r*   r+   z/_rollup_searchNr;   r<   r	   r
   r   r   r=   r>   r?   r@   r   r5   POSTr7   r   )r   r(   r;   r<   r	   r
   r   r   r=   r>   r?   r@   r   r9   r   r   r   r   r    rollup_search  s:   !

zRollupClient.rollup_searchc          	      C   r)   )z
        Starts an existing, stopped rollup job.

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

        :param id: Identifier for the rollup job.
        r   r   z/_startNr	   r
   r   r   r   r   rA   r   r   r   r   r   r    	start_jobW  s    zRollupClient.start_job)r	   r
   r   r   r/   wait_for_completionrD   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di}
| jd||	|
dS )a  
        Stops an existing, started rollup job.

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

        :param id: Identifier for the rollup job.
        :param timeout: If `wait_for_completion` is `true`, the API blocks for (at maximum)
            the specified duration while waiting for the job to stop. If more than `timeout`
            time has passed, the API throws a timeout exception.
        :param wait_for_completion: If set to `true`, causes the API to block until the
            indexer state completely stops. If set to `false`, the API returns immediately
            and the indexer is stopped asynchronously in the background.
        r   r   z/_stopNr	   r
   r   r   r/   rD   r   r   rA   r   r   )r   r   r	   r
   r   r   r/   rD   r   r   r   r   r   r    stop_joby  s(   zRollupClient.stop_job)__name__
__module____qualname__r   strtOptionalboolUnionSequencer   Anyr!   r%   r'   r,   Mappingintr:   rB   rC   rE   r   r   r   r    r      s   !#$#	
"j	
<!	
r   )typingrJ   Zelastic_transportr   _baser   utilsr   r   r   r   r   r   r   r    <module>   s
   