I have a JSON object with some of the fields like this:-
{
"desc": "this is test description",
"name": "some random name",
}
While indexing this document, I would like to change the field names and my document after indexing should look like this:-
{
"description": "this is test description",
"user_name": "some random name",
}
I've read about the Ingest pipeline processor but they only rename after a field is created. Is there any way that I could change the field names while indexing?
The way to do this is to use a Pipeline
. The general idea is you define the pipeline and give it a name on your cluster. Then you can reference it when indexing data and the data you send will be passed through that pipeline to transform it. Note pipelines will only run on nodes marked as "ingest" nodes.
https://www.elastic.co/guide/en/elasticsearch/reference/current/pipeline.html
To rename specifically, you can use this processor: https://www.elastic.co/guide/en/elasticsearch/reference/current/rename-processor.html
I didn't explicitly test this, but the code would be along the lines of:
Define the pipeline on your cluster with a name:
PUT _ingest/pipeline/my-pipeline-name
{
"description" : "rename user name",
"processors" : [
{
"rename" : {
"field": "name",
"target_field": "user_name"
},
"rename" : {
"field": "field2",
"target_field": "newfield2"
}
}
]
}
Load your doc, using the pipeline:
POST /some_index/_doc/?pipeline=my-pipeline-name
{
"desc": "this is test description",
"name": "some random name",
}