Aggregate multiple nested (recursive) logstash

Thank you very much for answering, answering your questions, yes, what I am trying to do is insert the subDetail array into the Detail array for each new document (id).
I understand what your idea is but I can't make it work, I tried several things similar to this but I didn't achieve the goal, what am I doing wrong?

    aggregate {
        task_id => "%{id}"
        code => "
            map['properties']['id'] = event.get('id')
            map['properties']['descripcion'] = event.get('description')            
                    
            map['properties']['detail_list'] ||= []
            map['properties']['Detail'] ||= []
            if (event.get('id_2') != nil) 
                if !( map['properties']['detail_list'].include?event.get('id_2') )
                        map['properties']['detail_list'] << event.get('id_2')                
                        map['properties']['Detail'] << {
                            'id_2' => event.get('id_2'),
                            'cod_2' => event.get('cod_2'),
                            'descr_2' => event.get('descr_2')                           
                        }
                        map['properties']['Detail'][id_2]['SubDetail'] << {
                                'id_3' => event.get('id_3'),
                                'cod_3' => event.get('cod_3'),
                                'descr_3' => event.get('descr_2')                            
                        }
                        
                end
            end 
            event.cancel()
        "
        push_previous_map_as_event => true
        timeout => 5
    } 

        ruby {
        code => "    
            newD = []
            event.get('[properties][Detail]').each { |k, v |
                newD << v
            }
            event.set('[properties][Detail]', newD)
        "
    }