# Create and add to a nested fields based on previous data in logstash

**URL:** <https://discuss.elastic.co/t/create-and-add-to-a-nested-fields-based-on-previous-data-in-logstash/80793>\
**Category:** Logstash\
**Created:** [March 31, 2017, 10:03am UTC](https://discuss.elastic.co/t/create-and-add-to-a-nested-fields-based-on-previous-data-in-logstash/80793 "2017-03-31T10:03:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Divya\_Bhardwaj](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/divya_bhardwaj/32/15231_2.png) [@Divya\_Bhardwaj](https://discuss.elastic.co/u/Divya_Bhardwaj)\
**Post date:** [March 31, 2017, 10:03am UTC](https://discuss.elastic.co/t/create-and-add-to-a-nested-fields-based-on-previous-data-in-logstash/80793/1 "2017-03-31T10:03:15Z")

</div>

Hi,  
I have a use case in which I have a data set with "Account Name" , "city", "country". My input is a .csv file.

Example data:

AccountName city country  
ABC CA GH  
XYZ LA CD  
ABC XY JH

Problem statement:  
whenever the same Account Name comes, I need to put the "city" and "country" in the array of "location" field.

My Mapping:

```auto
Put data
{
mappings:{
properties:{
"Account Name":{
type: text},
"location":{
properties:{
city:{
type: text
},
"country:{
type: text
}
}
}
}
}

```

Now the logstash file is:

```auto
input {

file 
}
filter{
mutate:
{

rename:
{
"City_" => "[location][City]"

"Country_" => "[location][Country]"
}
}}

output{

}

```

Please help me how to compare the pre-existing data with the new data.

Static comparison with if [Account Name]== %{Account Name}% doesn't help my case or may be I am missing something.

Thanks in advance

Best,

---

<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:** [April 28, 2017, 10:03am UTC](https://discuss.elastic.co/t/create-and-add-to-a-nested-fields-based-on-previous-data-in-logstash/80793/2 "2017-04-28T10:03:40Z")

</div>

Closed on April 28, 2017, 10:03am UTC

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