# How to create map with 0 length

**URL:** <https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093>\
**Category:** Logstash\
**Created:** [July 7, 2020, 5:32am UTC](https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093 "2020-07-07T05:32:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deepak\_Dandotiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak_dandotiya/32/31843_2.png) [@Deepak\_Dandotiya](https://discuss.elastic.co/u/Deepak_Dandotiya)\
**Post date:** [July 7, 2020, 5:32am UTC](https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093/1 "2020-07-07T05:32:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Deepak\_Dandotiya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/deepak_dandotiya/32/31843_2.png) [@Deepak\_Dandotiya](https://discuss.elastic.co/u/Deepak_Dandotiya)\
**Post date:** [July 7, 2020, 11:01am UTC](https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093/2 "2020-07-07T11:01:31Z")

</div>

@Badger @Fabio-sama

If possible please do help me

---

<div class="post-metadata">

**Author:** ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)\
**Post date:** [July 7, 2020, 11:42am UTC](https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093/3 "2020-07-07T11:42:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 4, 2020, 11:42am UTC](https://discuss.elastic.co/t/how-to-create-map-with-0-length/240093/4 "2020-08-04T11:42:39Z")

</div>

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