How to create map with 0 length

Hi All,

I need one help. how to create map with 0 length if data is null for that map fields. I am giving one example where student_key is PK and for a student creating SUBJECT as map so if all column data is null then I do not want to create map. Could anyone please do help me out at earliest as I need this for one of my usecase for production release.

```
input {
    jdbc {
        jdbc_driver_library => "<jdbc_driver_library>"
        jdbc_driver_class    => "<jdbc_driver_class>"
        jdbc_connection_string => "<jdbc_connection_string>"
        jdbc_user => "<username>"
        jdbc_password => "<password>"
        statement_filepath =>"<sql file path>"
       }
}

filter {
	kv { allow_duplicate_values => false }

    aggregate {
        task_id => "%{student_key}"
	code => "
			map['student_key']			= event.get('student_key')
			map['student_name']			= event.get('student_name')
			map['student_addr']			= event.get('student_addr')
			map['student_age']			= event.get('student_age')

			map['Subjects'] ||= []
			subj_data = {'subject_key' => event.get('subject_key'),'subjectcode' => event.get('subjectcode'),'subjectname' => event.get('subjectname'),'grade' => event.get('grade')}
			if ! map['Subjects'].include?(subj_data )
			map['Subjects'] << subj_data 
			end

				
       event.cancel()
       "
       push_previous_map_as_event => true
       timeout => 20
     }
   }

output {
    elasticsearch {
        index => "index_name_%{+YYYY_MM_dd}"
        hosts => [ "10.0.0.0:9200" ]
		document_id => "%{student_key}"
    }
}
```

Thanks,
Deepak

@Badger @Fabio-sama

If possible please do help me

Sorry man, I do not understand anything of what you wrote.

Let's make it simple. Paste here a sample of your input, a sample of your current output and a sample of your desired output.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.