Need to promote nested field to a higherlevel using logstash

Hi:
I have a mapping similar to this :

{
       "type1" : {
           "properties" : {
               "field1": {
                  "type": "nested",
                  "nested_field1": {
                     "type": "string"
                  },
                  "nested_field2": {
                    "type": "nested",
                    "properties": {
                       "sub_nested_field1" : {
                          "type" : "string"
                       }
                    }
                  }
            }
            }
            }
            }

I want to flatten out the document so that the mapping looks like so :

    {
       "type1" : {
           "properties" : {
               "field1": {
                  "type": "nested",
                  "nested_field1": {
                     "type": "string"
                  },
                  "sub_nested_field1" : {
                          "type" : "string"
                       }
    
            }
            }
            }
            }

I am using logstash to copy the data from one ES index to another. However, I have not been very successful at translating the required mapping.

input {
   elasticsearch {
     hosts => ["localhost"]
     port => "9200"
     index => "index1"
     scroll => "5m"
     docinfo => true
   }
}

filter {
  mutate {
        rename => {"field1" => "field1_old"}
    add_field => {
        "[field1_old][sub_nested_field1]" => "[entities_old][nested_field2][sub_nested_field1]"
    }
        remove_field => ["@timestamp","@version","[field1_old][nested_field2]"]
  }
}

output {
   elasticsearch {
     host => "localhost"
     port => 9300
     protocol => "transport"
     index => "index2"
     document_type => "type1"
     document_id => "%{[@metadata][_id]}"
   }
   stdout {
     codec => "dots"
   }
}

However I am having difficulty with this mapping. its not giving me he result I am expecting.. any help is much appreciated.

@Ramdev_Wudali

Hi, have you solved this issue ? I am facing a similar situation.
Kindly revert if you have a solution . Thanks!

Hi:
I had to skip solving this problem as the mapping/flattening would not have worked out for me and so I did not pursue this any further.

Ramdev

Okay :disappointed_relieved:
Thanks for the reply !