2017-03-28 17:23:01 -04:00
|
|
|
[[actions-index]]
|
|
|
|
=== Index Action
|
|
|
|
|
|
|
|
Use the `index` action to index data into Elasticsearch.
|
|
|
|
See <<index-action-attributes>> for the supported attributes.
|
|
|
|
|
|
|
|
==== Configuring Index Actions
|
|
|
|
|
|
|
|
The following snippet shows a simple `index` action definition:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
|
|
|
"actions" : {
|
|
|
|
"index_payload" : { <1>
|
|
|
|
"condition": { ... }, <2>
|
|
|
|
"transform": { ... }, <3>
|
|
|
|
"index" : {
|
|
|
|
"index" : "my-index", <4>
|
|
|
|
"doc_type" : "my-type", <5>
|
|
|
|
"doc_id": "my-id" <6>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
|
|
|
<1> The id of the action
|
|
|
|
<2> An optional <<condition, condition>> to restrict action execution
|
|
|
|
<3> An optional <<transform, transform>> to transform the payload and prepare the data that should be indexed
|
|
|
|
<4> The elasticsearch index to store the data to
|
|
|
|
<5> The document type to store the data as
|
|
|
|
<6> An optional `_id` for the document, if it should always be the same document.
|
|
|
|
|
|
|
|
|
|
|
|
[[index-action-attributes]]
|
|
|
|
==== Index Action Attributes
|
|
|
|
|
|
|
|
[options="header"]
|
|
|
|
|======
|
|
|
|
|Name |Required | Default | Description
|
|
|
|
|
|
|
|
| `index` | yes | - | The Elasticsearch index to index into.
|
|
|
|
|
|
|
|
| `doc_type` | yes | - | The type of the document the data will be indexed as.
|
|
|
|
|
|
|
|
| `doc_id` | no | - | The optional `_id` of the document.
|
|
|
|
|
|
|
|
| `execution_time_field` | no | - | The field that will store/index the watch execution
|
2017-09-26 16:26:02 -04:00
|
|
|
time.
|
2017-03-28 17:23:01 -04:00
|
|
|
|
|
|
|
| `timeout` | no | 60s | The timeout for waiting for the index api call to
|
|
|
|
return. If no response is returned within this time,
|
|
|
|
the index action times out and fails. This setting
|
|
|
|
overrides the default timeouts.
|
|
|
|
|
2017-12-21 05:41:57 -05:00
|
|
|
| `refresh` | no | - | Optional setting of the {ref}/docs-refresh.html[refresh policy]
|
2017-12-21 04:18:16 -05:00
|
|
|
for the write request
|
|
|
|
|
2017-03-28 17:23:01 -04:00
|
|
|
|======
|
|
|
|
|
|
|
|
[[anatomy-actions-index-multi-doc-support]]
|
|
|
|
==== Multi-Document Support
|
|
|
|
|
|
|
|
Like with all other actions, you can use a <<transform, transform>> to replace
|
|
|
|
the current execution context payload with another and by that change the document
|
|
|
|
that will end up indexed.
|
|
|
|
|
|
|
|
The index action plays well with transforms with its support for the special `_doc`
|
|
|
|
payload field.
|
|
|
|
|
|
|
|
When resolving the document to be indexed, the index action first looks up for a
|
|
|
|
`_doc` field in the payload. When not found, the payload is indexed as a single
|
|
|
|
document.
|
|
|
|
|
|
|
|
When a `_doc` field exists, if the field holds an object, it is extracted and indexed
|
|
|
|
as a single document. If the field holds an array of objects, each object is treated as
|
|
|
|
a document and the index action indexes all of them in a bulk.
|
|
|
|
|
2017-12-15 10:59:29 -05:00
|
|
|
An `_index`, `_type` or `_id` value can be added per document to dynamically set the ID
|
|
|
|
of the indexed document.
|