Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs example for Ingest scripts manipulating document metadata #24875

Merged
merged 1 commit into from
May 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
57 changes: 57 additions & 0 deletions docs/reference/ingest/ingest-node.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -1738,6 +1738,63 @@ numeric fields `field_a` and `field_b` multiplied by the parameter param_c:
--------------------------------------------------
// NOTCONSOLE

It is possible to use the Script Processor to manipulate document metadata like `_index` and `_type` during
ingestion. Here is an example of an Ingest Pipeline that renames the index and type to `my_index` no matter what
was provided in the original index request:

[source,js]
--------------------------------------------------
PUT _ingest/pipeline/my_index
{
"description": "use index:my_index and type:my_type",
"processors": [
{
"script": {
"inline": " ctx._index = 'my_index'; ctx._type = 'my_type' "
}
}
]
}
--------------------------------------------------
// CONSOLE

Using the above pipeline, we can attempt to index a document into the `any_index` index.

[source,js]
--------------------------------------------------
PUT any_index/any_type/1?pipeline=my_index
{
"message": "text"
}
--------------------------------------------------
// CONSOLE
// TEST[continued]

The response from the above index request:

[source,js]
--------------------------------------------------
{
"_index": "my_index",
"_type": "my_type",
"_id": "1",
"_version": 1,
"result": "created",
"_shards": {
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1,
"created": true
}
--------------------------------------------------
// TESTRESPONSE

In the above response, you can see that our document was actually indexed into `my_index` instead of
`any_index`. This type of manipulation is often convenient in pipelines that have various branches of transformation,
and depending on the progress made, indexed into different indices.

[[set-processor]]
=== Set Processor
Expand Down