3 ²˜‚]ß‹ã@s,ddlmZmZmZmZGdd„deƒZdS)é)ÚNamespacedClientÚ query_paramsÚ _make_pathÚ SKIP_IN_PATHc@s¤eZdZedddƒdˆdd„ƒZeƒd‰dd„ƒZeƒdŠd d „ƒZeƒd‹d d „ƒZedƒdŒd d„ƒZeƒd�dd„ƒZ eƒdŽdd„ƒZ eddƒd�dd„ƒZ eddƒd�dd„ƒZ eƒd‘dd„ƒZ edddddd d!d"d#d$dd%d&ƒ d’d'd(„ƒZed)d*d+d,d-ƒd“d.d/„ƒZed0d1ƒd”d2d3„ƒZed4d5d+d6d7d8d9d:d-ƒ d•d;d<„ƒZed+d8d=d9d-ƒd–d>d?„ƒZed8d9ƒd—d@dA„ƒZed8d9ƒd˜dBdC„ƒZedDƒd™dEdF„ƒZedDƒdšdGdH„ƒZed8d9ƒd›dIdJ„ƒZed5d+d6d8dKd9d:d-ƒdœdLdM„ƒZedƒd�dNdO„ƒZedƒdždPdQ„ƒZed5d+d8d9d:d-ƒdŸdRdS„ƒZeddTd+d6dUd-dVƒd dWdX„ƒZed5d+d6d8dYd9d:d-ƒd¡dZd[„ƒZeƒd¢d\d]„ƒZeƒd£d^d_„ƒZeƒd¤d`da„ƒZ edbdcƒd¥ddde„ƒZ!eƒd¦dfdg„ƒZ"eƒd§dhdi„ƒZ#eƒd¨djdk„ƒZ$eƒd©dldm„ƒZ%eƒdªdndo„ƒZ&eƒd«dpdq„ƒZ'edrƒd¬dsdt„ƒZ(edudƒd­dvdw„ƒZ)ed+d-dƒd®dxdy„ƒZ*edDddƒd¯dzd{„ƒZ+eƒd°d|d}„ƒZ,eƒd±d~d„ƒZ-eƒd²d€d�„ƒZ.eƒd³d‚dƒ„ƒZ/eƒd´d„d…„ƒZ0eƒdµd†d‡„ƒZ1dS)¶ÚMlClientZ allow_no_jobsÚforceÚtimeoutNcCs.|tkrtdƒ‚|jjdtdd|dƒ||d�S)a4 ``_ :arg job_id: The name of the job to close :arg body: The URL params optionally sent in the body :arg allow_no_jobs: Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) :arg force: True if the job should be forcefully closed :arg timeout: Controls the time to wait until a job has closed. Default to 30 minutes z4Empty value passed for a required argument 'job_id'.ÚPOSTÚ_mlÚanomaly_detectorsÚ_close)ÚparamsÚbody)rÚ ValueErrorÚ transportÚperform_requestr)ÚselfÚjob_idrr ©rúF/tmp/pip-build-z81i1n8o/elasticsearch/elasticsearch/client/xpack/ml.pyÚ close_jobs zMlClient.close_jobcCs*|tkrtdƒ‚|jjdtdd|ƒ|d�S)zS `<>`_ :arg calendar_id: The ID of the calendar to delete z9Empty value passed for a required argument 'calendar_id'.ÚDELETEr Ú calendars)r )rrrrr)rÚ calendar_idr rrrÚdelete_calendars zMlClient.delete_calendarcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|d|ƒ|d�S)zš `<>`_ :arg calendar_id: The ID of the calendar to modify :arg event_id: The ID of the event to remove from the calendar z+Empty value passed for a required argument.rr rÚevents)r )rrrrr)rrZevent_idr ÚparamrrrÚdelete_calendar_event+s zMlClient.delete_calendar_eventcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|d|ƒ|d�S)z– `<>`_ :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID of the job to remove from the calendar z+Empty value passed for a required argument.rr rÚjobs)r )rrrrr)rrrr rrrrÚdelete_calendar_job<s zMlClient.delete_calendar_jobcCs*|tkrtdƒ‚|jjdtdd|ƒ|d�S)zï ``_ :arg datafeed_id: The ID of the datafeed to delete :arg force: True if the datafeed should be forcefully deleted z9Empty value passed for a required argument 'datafeed_id'.rr Ú datafeeds)r )rrrrr)rÚ datafeed_idr rrrÚdelete_datafeedMs zMlClient.delete_datafeedcCs|jjdd|d�S)z `<>`_ rz/_ml/_delete_expired_data)r )rr)rr rrrÚdelete_expired_data]szMlClient.delete_expired_datacCs*|tkrtdƒ‚|jjdtdd|ƒ|d�S)zO `<>`_ :arg filter_id: The ID of the filter to delete z7Empty value passed for a required argument 'filter_id'.rr Úfilters)r )rrrrr)rÚ filter_idr rrrÚ delete_filterfszMlClient.delete_filterZallow_no_forecastscCs.|tkrtdƒ‚|jjdtdd|d|ƒ|d�S)a  ``_ :arg job_id: The ID of the job from which to delete forecasts :arg forecast_id: The ID of the forecast to delete, can be comma delimited list. Leaving blank implies `_all` :arg allow_no_forecasts: Whether to ignore if `_all` matches no forecasts :arg timeout: Controls the time to wait until the forecast(s) are deleted. Default to 30 seconds z4Empty value passed for a required argument 'job_id'.rr r Ú _forecast)r )rrrrr)rrZ forecast_idr rrrÚdelete_forecastss zMlClient.delete_forecastZwait_for_completioncCs*|tkrtdƒ‚|jjdtdd|ƒ|d�S)ar ``_ :arg job_id: The ID of the job to delete :arg force: True if the job should be forcefully deleted, default False :arg wait_for_completion: Should this request wait until the operation has completed before returning, default True z4Empty value passed for a required argument 'job_id'.rr r )r )rrrrr)rrr rrrÚ delete_jobˆs zMlClient.delete_jobcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|d|ƒ|d�S)zÙ ``_ :arg job_id: The ID of the job to fetch :arg snapshot_id: The ID of the snapshot to delete z+Empty value passed for a required argument.rr r Úmodel_snapshots)r )rrrrr)rrÚ snapshot_idr rrrrÚdelete_model_snapshot˜s  zMlClient.delete_model_snapshotÚcharsetZ column_namesÚ delimiterZexplainÚformatZ grok_patternZhas_header_rowZlines_to_sampleÚquoteZshould_trim_fieldsZtimestamp_fieldZtimestamp_formatcCs,|tkrtdƒ‚|jjdd||jj|ƒd�S)a‹ ``_ :arg body: The contents of the file to be analyzed :arg charset: Optional parameter to specify the character set of the file :arg column_names: Optional parameter containing a comma separated list of the column names for a delimited file :arg delimiter: Optional parameter to specify the delimiter character for a delimited file - must be a single character :arg explain: Whether to include a commentary on how the structure was derived, default False :arg format: Optional parameter to specify the high level file format, valid choices are: 'ndjson', 'xml', 'delimited', 'semi_structured_text' :arg grok_pattern: Optional parameter to specify the Grok pattern that should be used to extract fields from messages in a semi-structured text file :arg has_header_row: Optional parameter to specify whether a delimited file includes the column names in its first row :arg lines_to_sample: How many lines of the file should be included in the analysis, default 1000 :arg quote: Optional parameter to specify the quote character for a delimited file - must be a single character :arg should_trim_fields: Optional parameter to specify whether the values between delimiters in a delimited file should have whitespace trimmed from them :arg timeout: Timeout after which the analysis will be aborted, default '25s' :arg timestamp_field: Optional parameter to specify the timestamp field in the file :arg timestamp_format: Optional parameter to specify the timestamp format in the file - may be either a Joda or Java time format z2Empty value passed for a required argument 'body'.r z/_ml/find_file_structure)r r)rrrrÚclientÚ _bulk_body)rrr rrrÚfind_file_structure«s2zMlClient.find_file_structureZ advance_timeZ calc_interimÚendZ skip_timeÚstartcCs.|tkrtdƒ‚|jjdtdd|dƒ||d�S)a| ``_ :arg job_id: The name of the job to flush :arg body: Flush parameters :arg advance_time: Advances time to the given value generating results and updating the model for the advanced interval :arg calc_interim: Calculates interim results for the most recent bucket or all buckets within the latency period :arg end: When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results :arg skip_time: Skips time to the given value without generating results or updating the model for the skipped interval :arg start: When used in conjunction with calc_interim, specifies the range of buckets on which to calculate interim results z4Empty value passed for a required argument 'job_id'.r r r Ú_flush)r r)rrrrr)rrrr rrrÚ flush_jobæs zMlClient.flush_jobÚdurationZ expires_incCs,|tkrtdƒ‚|jjdtdd|dƒ|d�S)a `<>`_ :arg job_id: The ID of the job to forecast for :arg duration: The duration of the forecast :arg expires_in: The time interval after which the forecast expires. Expired forecasts will be deleted at the first opportunity. z4Empty value passed for a required argument 'job_id'.r r r r')r )rrrrr)rrr rrrÚforecasts  zMlClient.forecastZ anomaly_scoreÚdescZexclude_interimÚexpandÚfrom_ÚsizeÚsortc Cs2|tkrtdƒ‚|jjdtdd|dd|ƒ||d�S)a ``_ :arg job_id: ID of the job to get bucket results from :arg timestamp: The timestamp of the desired single bucket result :arg body: Bucket selection details if not provided in URI :arg anomaly_score: Filter for the most anomalous buckets :arg desc: Set the sort direction :arg end: End time filter for buckets :arg exclude_interim: Exclude interim results :arg expand: Include anomaly records :arg from_: skips a number of buckets :arg size: specifies a max number of buckets to get :arg sort: Sort buckets by a particular field :arg start: Start time filter for buckets z4Empty value passed for a required argument 'job_id'.ÚGETr r ÚresultsZbuckets)r r)rrrrr)rrÚ timestamprr rrrÚ get_bucketsszMlClient.get_bucketsrcCs,|tkrtdƒ‚|jjdtdd|dƒ|d�S)a‘ `<>`_ :arg calendar_id: The ID of the calendar containing the events :arg end: Get events before this time :arg from_: Skips a number of events :arg job_id: Get events for the job. When this option is used calendar_id must be '_all' :arg size: Specifies a max number of events to get :arg start: Get events after this time z9Empty value passed for a required argument 'calendar_id'.r?r rr)r )rrrrr)rrr rrrÚget_calendar_events:s zMlClient.get_calendar_eventscCs|jjdtdd|ƒ||d�S)a  `<>`_ :arg calendar_id: The ID of the calendar to fetch :arg body: The from and size parameters optionally sent in the body :arg from_: skips a number of calendars :arg size: specifies a max number of calendars to get r?r r)r r)rrr)rrrr rrrÚ get_calendarsOs zMlClient.get_calendarsc Cs2|tkrtdƒ‚|jjdtdd|dd|ƒ||d�S)a™ ``_ :arg job_id: The name of the job :arg category_id: The identifier of the category definition of interest :arg body: Category selection details if not provided in URI :arg from_: skips a number of categories :arg size: specifies a max number of categories to get z4Empty value passed for a required argument 'job_id'.r?r r r@Ú categories)r r)rrrrr)rrZ category_idrr rrrÚget_categories]s zMlClient.get_categoriesZallow_no_datafeedscCs|jjdtdd|dƒ|d�S)as ``_ :arg datafeed_id: The ID of the datafeeds stats to fetch :arg allow_no_datafeeds: Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) r?r r Ú_stats)r )rrr)rr!r rrrÚget_datafeed_statsss zMlClient.get_datafeed_statscCs|jjdtdd|ƒ|d�S)ag ``_ :arg datafeed_id: The ID of the datafeeds to fetch :arg allow_no_datafeeds: Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) r?r r )r )rrr)rr!r rrrÚ get_datafeeds�s zMlClient.get_datafeedscCs|jjdtdd|ƒ|d�S)z¸ `<>`_ :arg filter_id: The ID of the filter to fetch :arg from_: skips a number of filters :arg size: specifies a max number of filters to get r?r r$)r )rrr)rr%r rrrÚ get_filters�s zMlClient.get_filtersZinfluencer_scorecCs0|tkrtdƒ‚|jjdtdd|ddƒ||d�S)aË ``_ :arg job_id: None :arg body: Influencer selection criteria :arg desc: whether the results should be sorted in decending order :arg end: end timestamp for the requested influencers :arg exclude_interim: Exclude interim results :arg from_: skips a number of influencers :arg influencer_score: influencer score threshold for the requested influencers :arg size: specifies a max number of influencers to get :arg sort: sort field for the requested influencers :arg start: start timestamp for the requested influencers z4Empty value passed for a required argument 'job_id'.r?r r r@Z influencers)r r)rrrrr)rrrr rrrÚget_influencersœszMlClient.get_influencerscCs|jjdtdd|dƒ|d�S)aU ``_ :arg job_id: The ID of the jobs stats to fetch :arg allow_no_jobs: Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) r?r r rG)r )rrr)rrr rrrÚ get_job_stats¿s  zMlClient.get_job_statscCs|jjdtdd|ƒ|d�S)aI ``_ :arg job_id: The ID of the jobs to fetch :arg allow_no_jobs: Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) r?r r )r )rrr)rrr rrrÚget_jobsÏs zMlClient.get_jobscCs0|tkrtdƒ‚|jjdtdd|d|ƒ||d�S)a€ ``_ :arg job_id: The ID of the job to fetch :arg snapshot_id: The ID of the snapshot to fetch :arg body: Model snapshot selection criteria :arg desc: True if the results should be sorted in descending order :arg end: The filter 'end' query parameter :arg from_: Skips a number of documents :arg size: The default number of documents returned in queries as a string. :arg sort: Name of the field to sort on :arg start: The filter 'start' query parameter z4Empty value passed for a required argument 'job_id'.r?r r r*)r r)rrrrr)rrr+rr rrrÚget_model_snapshotsÝs zMlClient.get_model_snapshotsZ bucket_spanZ overall_scoreZtop_ncCs0|tkrtdƒ‚|jjdtdd|ddƒ||d�S)a ``_ :arg job_id: The job IDs for which to calculate overall bucket results :arg body: Overall bucket selection details if not provided in URI :arg allow_no_jobs: Whether to ignore if a wildcard expression matches no jobs. (This includes `_all` string or when no jobs have been specified) :arg bucket_span: The span of the overall buckets. Defaults to the longest job bucket_span :arg end: Returns overall buckets with timestamps earlier than this time :arg exclude_interim: If true overall buckets that include interim buckets will be excluded :arg overall_score: Returns overall buckets with overall scores higher than this value :arg start: Returns overall buckets with timestamps after this time :arg top_n: The number of top job bucket scores to be used in the overall_score calculation z4Empty value passed for a required argument 'job_id'.r?r r r@Zoverall_buckets)r r)rrrrr)rrrr rrrÚget_overall_bucketsøs zMlClient.get_overall_bucketsZ record_scorecCs0|tkrtdƒ‚|jjdtdd|ddƒ||d�S)a+ ``_ :arg job_id: None :arg body: Record selection criteria :arg desc: Set the sort direction :arg end: End time filter for records :arg exclude_interim: Exclude interim results :arg from_: skips a number of records :arg record_score: :arg size: specifies a max number of records to get :arg sort: Sort records by a particular field :arg start: Start time filter for records z4Empty value passed for a required argument 'job_id'.r?r r r@Úrecords)r r)rrrrr)rrrr rrrÚ get_records szMlClient.get_recordscCs|jjdd|d�S)z `<>`_ r?z /_ml/info)r )rr)rr rrrÚinfoBsz MlClient.infocCs,|tkrtdƒ‚|jjdtdd|dƒ|d�S)z– ``_ :arg job_id: The ID of the job to open z4Empty value passed for a required argument 'job_id'.r r r Ú_open)r )rrrrr)rrr rrrÚopen_jobIs  zMlClient.open_jobcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|dƒ||d�S)zw `<>`_ :arg calendar_id: The ID of the calendar to modify :arg body: A list of events z+Empty value passed for a required argument.r r rr)r r)rrrrr)rrrr rrrrÚpost_calendar_eventsXs  zMlClient.post_calendar_eventsZ reset_endZ reset_startcCsHx ||fD]}|tkr tdƒ‚q W|jjdtdd|dƒ||jj|ƒd�S)aŸ ``_ :arg job_id: The name of the job receiving the data :arg body: The data to process :arg reset_end: Optional parameter to specify the end of the bucket resetting range :arg reset_start: Optional parameter to specify the start of the bucket resetting range z+Empty value passed for a required argument.r r r Ú_data)r r)rrrrrr1r2)rrrr rrrrÚ post_datajs   zMlClient.post_datacCs,|tkrtdƒ‚|jjdtdd|dƒ|d�S)z« ``_ :arg datafeed_id: The ID of the datafeed to preview z9Empty value passed for a required argument 'datafeed_id'.r?r r Z_preview)r )rrrrr)rr!r rrrÚpreview_datafeed€s zMlClient.preview_datafeedcCs,|tkrtdƒ‚|jjdtdd|ƒ||d�S)z{ `<>`_ :arg calendar_id: The ID of the calendar to create :arg body: The calendar details z9Empty value passed for a required argument 'calendar_id'.ÚPUTr r)r r)rrrrr)rrrr rrrÚ put_calendar‘s zMlClient.put_calendarcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|d|ƒ|d�S)z‘ `<>`_ :arg calendar_id: The ID of the calendar to modify :arg job_id: The ID of the job to add to the calendar z+Empty value passed for a required argument.rYr rr)r )rrrrr)rrrr rrrrÚput_calendar_job¡s zMlClient.put_calendar_jobcCs>x ||fD]}|tkr tdƒ‚q W|jjdtdd|ƒ||d�S)zÍ ``_ :arg datafeed_id: The ID of the datafeed to create :arg body: The datafeed config z+Empty value passed for a required argument.rYr r )r r)rrrrr)rr!rr rrrrÚ put_datafeed²s  zMlClient.put_datafeedcCs>x ||fD]}|tkr tdƒ‚q W|jjdtdd|ƒ||d�S)zu `<>`_ :arg filter_id: The ID of the filter to create :arg body: The filter details z+Empty value passed for a required argument.rYr r$)r r)rrrrr)rr%rr rrrrÚ put_filterÁs  zMlClient.put_filtercCs>x ||fD]}|tkr tdƒ‚q W|jjdtdd|ƒ||d�S)z² ``_ :arg job_id: The ID of the job to create :arg body: The job z+Empty value passed for a required argument.rYr r )r r)rrrrr)rrrr rrrrÚput_jobÐs  zMlClient.put_jobZdelete_intervening_resultsc CsDx ||fD]}|tkr tdƒ‚q W|jjdtdd|d|dƒ||d�S)at ``_ :arg job_id: The ID of the job to fetch :arg snapshot_id: The ID of the snapshot to revert to :arg body: Reversion options :arg delete_intervening_results: Should we reset the results back to the time of the snapshot? z+Empty value passed for a required argument.r r r r*Z_revert)r r)rrrrr)rrr+rr rrrrÚrevert_model_snapshotâs  zMlClient.revert_model_snapshotZenabledcCs|jjdd|d�S)aB ``_ :arg enabled: Whether to enable upgrade_mode ML setting or not. Defaults to false. :arg timeout: Controls the time to wait before action times out. Defaults to 30 seconds r z/_ml/set_upgrade_mode)r )rr)rr rrrÚset_upgrade_modeþs zMlClient.set_upgrade_modecCs.|tkrtdƒ‚|jjdtdd|dƒ||d�S)a  ``_ :arg datafeed_id: The ID of the datafeed to start :arg body: The start datafeed parameters :arg end: The end time when the datafeed should stop. When not set, the datafeed continues in real time :arg start: The start time from where the datafeed should begin :arg timeout: Controls the time to wait until a datafeed has started. Default to 20 seconds z9Empty value passed for a required argument 'datafeed_id'.r r r Z_start)r r)rrrrr)rr!rr rrrÚstart_datafeed s  zMlClient.start_datafeedcCs,|tkrtdƒ‚|jjdtdd|dƒ|d�S)a ``_ :arg datafeed_id: The ID of the datafeed to stop :arg allow_no_datafeeds: Whether to ignore if a wildcard expression matches no datafeeds. (This includes `_all` string or when no datafeeds have been specified) :arg force: True if the datafeed should be forcefully stopped. :arg timeout: Controls the time to wait until a datafeed has stopped. Default to 20 seconds z9Empty value passed for a required argument 'datafeed_id'.r r r Ú_stop)r )rrrrr)rr!r rrrÚ stop_datafeed$s zMlClient.stop_datafeedcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|dƒ||d�S)zÙ ``_ :arg datafeed_id: The ID of the datafeed to update :arg body: The datafeed update settings z+Empty value passed for a required argument.r r r Ú_update)r r)rrrrr)rr!rr rrrrÚupdate_datafeed9s  zMlClient.update_datafeedcCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|dƒ||d�S)zt `<>`_ :arg filter_id: The ID of the filter to update :arg body: The filter update z+Empty value passed for a required argument.r r r$rd)r r)rrrrr)rr%rr rrrrÚ update_filterKs  zMlClient.update_filtercCs@x ||fD]}|tkr tdƒ‚q W|jjdtdd|dƒ||d�S)zÅ ``_ :arg job_id: The ID of the job to create :arg body: The job update settings z+Empty value passed for a required argument.r r r rd)r r)rrrrr)rrrr rrrrÚ update_job]s  zMlClient.update_jobc CsFx"|||fD]}|tkr tdƒ‚q W|jjdtdd|d|dƒ||d�S)a ``_ :arg job_id: The ID of the job to fetch :arg snapshot_id: The ID of the snapshot to update :arg body: The model snapshot properties to update z+Empty value passed for a required argument.r r r r*rd)r r)rrrrr)rrr+rr rrrrÚupdate_model_snapshotos  zMlClient.update_model_snapshotcCs$|tkrtdƒ‚|jjdd||d�S)z: `<>`_ :arg body: The job config z2Empty value passed for a required argument 'body'.r z /_ml/anomaly_detectors/_validate)r r)rrrr)rrr rrrÚvalidate‰szMlClient.validatecCs$|tkrtdƒ‚|jjdd||d�S)z8 `<>`_ :arg body: The detector z2Empty value passed for a required argument 'body'.r z)/_ml/anomaly_detectors/_validate/detector)r r)rrrr)rrr rrrÚvalidate_detector–szMlClient.validate_detector)NN)N)N)N)N)N)N)NN)N)N)N)NN)N)NNN)N)NNN)NNN)NN)NN)NN)NN)NN)NN)NNN)NN)NN)N)N)N)N)N)NN)N)N)N)N)NN)N)NN)N)N)N)N)N)N)N)2Ú__name__Ú __module__Ú __qualname__rrrrrr"r#r&r(r)r,r3r7r9rBrCrDrFrHrIrJrKrLrMrNrOrQrRrTrUrWrXrZr[r\r]r^r_r`rarcrerfrgrhrirjrrrrrs            ,                                   rN)ÚutilsrrrrrrrrrÚs