[[reference-ml-put_datafeed]]

////////
===========================================================================================================================
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
||        ██████╗ ███████╗ █████╗ ██████╗ ███╗   ███╗███████╗                                                            ||
||        ██╔══██╗██╔════╝██╔══██╗██╔══██╗████╗ ████║██╔════╝                                                            ||
||        ██████╔╝█████╗  ███████║██║  ██║██╔████╔██║█████╗                                                              ||
||        ██╔══██╗██╔══╝  ██╔══██║██║  ██║██║╚██╔╝██║██╔══╝                                                              ||
||        ██║  ██║███████╗██║  ██║██████╔╝██║ ╚═╝ ██║███████╗                                                            ||
||        ╚═╝  ╚═╝╚══════╝╚═╝  ╚═╝╚═════╝ ╚═╝     ╚═╝╚══════╝                                                            ||
||                                                                                                                       ||
||                                                                                                                       ||
||    This file is autogenerated, DO NOT send pull requests that changes this file directly.                             ||
||    You should update the script that does the generation, which can be found in:                                      ||
||    https://github.com/elastic/elastic-client-generator-js                                                             ||
||                                                                                                                       ||
||    You can run the script with the following command:                                                                 ||
||       npm run elasticsearch -- --version <version>                                                                    ||
||                                                                                                                       ||
||                                                                                                                       ||
||                                                                                                                       ||
===========================================================================================================================
////////

[discrete]
=== client.ml.putDatafeed

Create a datafeed. Datafeeds retrieve data from Elasticsearch for analysis by an anomaly detection job. You can associate only one datafeed with each anomaly detection job. The datafeed contains a query that runs at a defined interval (`frequency`). If you are concerned about delayed data, you can add a delay (`query_delay') at each interval. When 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. You must use Kibana, this API, or the create anomaly detection jobs API to create a datafeed. Do not add a datafeed directly to the `.ml-config` index. Do not give users `write` privileges on the `.ml-config` index.

{ref}/ml-put-datafeed.html[{es} documentation]

[discrete]
==== Function signature

[source,ts]
----
(MlPutDatafeedRequest, options?): Promise<MlPutDatafeedResponse>
----

[discrete]
===== `MlPutDatafeedRequest`

[source,ts]
----
interface MlPutDatafeedRequest extends <<shared-type-request-base, RequestBase>> {
  datafeed_id: <<shared-type-id, Id>>
  allow_no_indices?: boolean
  expand_wildcards?: <<shared-type-expand-wildcards, ExpandWildcards>>
  ignore_throttled?: boolean
  ignore_unavailable?: boolean
  aggregations?: Record<string, AggregationsAggregationContainer>
  chunking_config?: MlChunkingConfig
  delayed_data_check_config?: MlDelayedDataCheckConfig
  frequency?: <<shared-type-duration, Duration>>
  indices?: <<shared-type-indices, Indices>>
  /** @alias indices */
  indexes?: <<shared-type-indices, Indices>>
  indices_options?: <<shared-type-indices-options, IndicesOptions>>
  job_id?: <<shared-type-id, Id>>
  max_empty_searches?: <<shared-type-integer, integer>>
  query?: QueryDslQueryContainer
  query_delay?: <<shared-type-duration, Duration>>
  runtime_mappings?: MappingRuntimeFields
  script_fields?: Record<string, <<shared-type-script-field, ScriptField>>>
  scroll_size?: <<shared-type-integer, integer>>
  headers?: <<shared-type-http-headers, HttpHeaders>>
}
----

[discrete]
===== `MlPutDatafeedResponse`

[source,ts]
----
interface MlPutDatafeedResponse {
  aggregations?: Record<string, AggregationsAggregationContainer>
  authorization?: MlDatafeedAuthorization
  chunking_config: MlChunkingConfig
  delayed_data_check_config?: MlDelayedDataCheckConfig
  datafeed_id: <<shared-type-id, Id>>
  frequency?: <<shared-type-duration, Duration>>
  indices: string[]
  job_id: <<shared-type-id, Id>>
  indices_options?: <<shared-type-indices-options, IndicesOptions>>
  max_empty_searches?: <<shared-type-integer, integer>>
  query: QueryDslQueryContainer
  query_delay: <<shared-type-duration, Duration>>
  runtime_mappings?: MappingRuntimeFields
  script_fields?: Record<string, <<shared-type-script-field, ScriptField>>>
  scroll_size: <<shared-type-integer, integer>>
}
----

