<commit_before>[role="xpack"]
[[ml-post-data]]
=== Post Data to Jobs

The post data API enables you to send data to an anomaly detection job for analysis.


==== Request

`POST _xpack/ml/anomaly_detectors/<job_id>/_data --data-binary @<data-file.json>`


==== Description

The job must have a state of `open` to receive and process the data.

The data that you send to the job must use the JSON format.

File sizes are limited to 100 Mb. If your file is larger, split it into multiple
files and upload each one separately in sequential time order. When running in
real time, it is generally recommended that you perform many small uploads,
rather than queueing data to upload larger files.

When uploading data, check the <<ml-datacounts,job data counts>> for progress.
The following records will not be processed:

* Records not in chronological order and outside the latency window
* Records with an invalid timestamp

//TBD link to Working with Out of Order timeseries concept doc

IMPORTANT:  Data can only be accepted from a single connection. Use a single
connection synchronously to send data, close, flush, or delete a single job.
It is not currently possible to post data to multiple jobs using wildcards
or a comma-separated list.


==== Path Parameters

`job_id` (required)::
		(string) Identifier for the job


==== Request Body

`reset_start`::
		(string) Specifies the start of the bucket resetting range

`reset_end`::
		(string) Specifies the end of the bucket resetting range


==== Authorization

You must have `manage_ml`, or `manage` cluster privileges to use this API.
For more information, see
{xpack-ref}/security-privileges.html[Security Privileges].
//<<privileges-list-cluster>>.


==== Examples

The following example posts data from the farequote.json file to the `farequote` job:

[source,js]
--------------------------------------------------
$ curl -s -H "Content-type: application/json"
-X POST http:\/\/localhost:9200/_xpack/ml/anomaly_detectors/it_ops_new_kpi/_data
--data-binary @it_ops_new_kpi.json
--------------------------------------------------

//TBD: Create example of how to post a small data example in Kibana?

When the data is sent, you receive information about the operational progress of the job.
For example:

[source,js]
----
{
	"job_id":"it_ops_new_kpi",
	"processed_record_count":21435,
	"processed_field_count":64305,
	"input_bytes":2589063,
	"input_field_count":85740,
	"invalid_date_count":0,
	"missing_field_count":0,
	"out_of_order_timestamp_count":0,
	"empty_bucket_count":16,
	"sparse_bucket_count":0,
	"bucket_count":2165,<commit_msg>[DOCS] Fix ML post_data docs (elastic/x-pack-elasticsearch#2689)<commit_after>[role="xpack"]
[[ml-post-data]]
=== Post Data to Jobs

The post data API enables you to send data to an anomaly detection job for analysis.


==== Request

`POST _xpack/ml/anomaly_detectors/<job_id>/_data`


==== Description

The job must have a state of `open` to receive and process the data.

The data that you send to the job must use the JSON format. Multiple JSON
documents can be sent, either adjacent with no separator in between them or
whitespace separated. Newline delimited JSON (NDJSON) is a possible whitespace
separated format, and for this the `Content-Type` header should be set to
`application/x-ndjson`.

Upload sizes are limited to the Elasticsearch HTTP receive buffer size
(default 100 Mb). If your data is larger, split it into multiple chunks
and upload each one separately in sequential time order. When running in
real time, it is generally recommended that you perform many small uploads,
rather than queueing data to upload larger files.

When uploading data, check the <<ml-datacounts,job data counts>> for progress.
The following records will not be processed:

* Records not in chronological order and outside the latency window
* Records with an invalid timestamp

//TBD link to Working with Out of Order timeseries concept doc

IMPORTANT:  For each job, data can only be accepted from a single connection at
a time. It is not currently possible to post data to multiple jobs using wildcards
or a comma-separated list.


==== Path Parameters

`job_id` (required)::
		(string) Identifier for the job


==== Query Parameters

`reset_start`::
		(string) Specifies the start of the bucket resetting range

`reset_end`::
		(string) Specifies the end of the bucket resetting range


==== Request Body

A sequence of one or more JSON documents containing the data to be analyzed.
Only whitespace characters are permitted in between the documents.


==== Authorization

You must have `manage_ml`, or `manage` cluster privileges to use this API.
For more information, see
{xpack-ref}/security-privileges.html[Security Privileges].
//<<privileges-list-cluster>>.


==== Examples

The following example posts data from the it_ops_new_kpi.json file to the `it_ops_new_kpi` job:

[source,js]
--------------------------------------------------
$ curl -s -H "Content-type: application/json"
-X POST http:\/\/localhost:9200/_xpack/ml/anomaly_detectors/it_ops_new_kpi/_data
--data-binary @it_ops_new_kpi.json
--------------------------------------------------

When the data is sent, you receive information about the operational progress of the job.
For example:

[source,js]
----
{
	"job_id":"it_ops_new_kpi",
	"processed_record_count":21435,
	"processed_field_count":64305,
	"input_bytes":2589063,
	"input_field_count":85740,
	"invalid_date_count":0,
	"missing_field_count":0,
	"out_of_order_timestamp_count":0,
	"empty_bucket_count":16,
	"sparse_bucket_count":0,
	"bucket_count":2165,
{'fraction_non_alphanumeric': 0.1197776582391967, 'fraction_numerical': 0.014703245472476242, 'mean_word_length': 3.9937332139659802, 'pattern_counts': {'":': 22, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1772088', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1591, 'n_words': 664}