Put pipeline API

This API is used to define a new pipeline. This API is also used to add a new pipeline or update an existing pipeline.

Let's look at an example. As we can see in the following code, we have defined a new pipeline named firstpipeline, which converts the value present in the message field into upper case:

curl -X PUT http://localhost:9200/_ingest/pipeline/firstpipeline -H 'content-type: application/json'  
-d '{
"description" : "uppercase the incoming value in the message field",
"processors" : [
{
"uppercase" : {
"field": "message"
}
}
]
}'

When creating a pipeline, multiple processors can be defined, and the order of the execution depends on the order in which it is defined in the definition. Let's look at an example for this. As we can see in the following code, we have created a new pipeline called secondpipeline that converts the uppercase value present in the message field and renames the message field to data. It creates a new field named label with the testlabel value:

curl -X PUT http://localhost:9200/_ingest/pipeline/secondpipeline -H 'content-type: application/json'
-d '{
"description" : "uppercase the incoming value in the message field",
"processors" : [
{
"uppercase" : {
"field": "message",
"ignore_failure" : true
}
},
{
"rename": {
"field": "message",
"target_field": "data",
"ignore_failure" : true
}
},
{
"set": {
"field": "label",
"value": "testlabel",
"override": false
}
}

]
}'

Let's make use of the second pipeline to index a sample document:

curl -X PUT 'http://localhost:9200/myindex/mytpe/1?pipeline=secondpipeline' -H 'content-type: application/json' -d '{
"message":"elk is awesome"
}'

Let's retrieve the same document and validate the transformation:

curl -X GET   http://localhost:9200/myindex/mytpe/1   -H 'content-type: application/json' 

Response:
{
"_index": "myindex",
"_type": "mytpe",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"label": "testlabel",
"data": "ELK IS AWESOME"
}
}
If the field that's used in the processor is missing, then the processor throws an exception and the document won't be indexed. In order to prevent the processor from throwing an exception, we can make use of the "ignore_failure" : true parameter.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset