# Create nested object mapping using logstash unloading from postgres

**URL:** https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661
**Category:** Elasticsearch
**Created:** [June 20, 2022, 1:45pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661 "2022-06-20T13:45:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![anand\_tripathi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_tripathi/32/107286_2.png) [@anand\_tripathi](https://discuss.elastic.co/u/anand_tripathi)
#### Post date: [June 20, 2022, 1:45pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661/1 "2022-06-20T13:45:33Z")

</div>

Hi, I am unloading data from Postgres to Elasticsearch using logstash. In this case if the index is not there in Elasticsearch logstash is creating an index with the predefined mapping. The mapping is perfect for all the data.

But for one specific array of objects in the document I need that to be nested datatype. Can do that with some filter of logstash

For example

```auto
"members": {
          "properties": {
            "applicant": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "application_dt": {
              "type": "date"
            }
         }
 }

```

This is the above mapping of one array key that is members. I want this to automatically be a nested datatype on creation  
It looks like this

```auto
{
....,
members: [
    {applicant: 'Name', application_dt: '2009-01-01'},
    ....
]
....
}

```

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 20, 2022, 1:55pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661/2 "2022-06-20T13:55:33Z")

</div>

> [@anand\_tripathi](#):
>
> In this case if the index is not there in Elasticsearch logstash is creating an index with the predefined mapping.

DId you create a template or are you letting elasticsearch create the mapping?

If you create a template, then you will need to change the mapping in your template, if you are letting elasticsearch create the mapping, then you will need to create an [index template](https://www.elastic.co/guide/en/elasticsearch/reference/current/index-templates.html) to apply the correct mapping.

---

<div class="post-metadata">

### Author: ![anand\_tripathi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anand_tripathi/32/107286_2.png) [@anand\_tripathi](https://discuss.elastic.co/u/anand_tripathi)
#### Post date: [June 20, 2022, 2:14pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661/3 "2022-06-20T14:14:52Z")

</div>

So either way I have to create a template for it I guess. It cannot be done without the template or by using some filters or changing the value to some specific datatype. I have to maintain a template before creating records in Elasticsearch correct?

---

<div class="post-metadata">

### Author: ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)
#### Post date: [June 20, 2022, 2:24pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661/4 "2022-06-20T14:24:35Z")

</div>

Yes, if you want that field to be of `nested` type, you will need to create a template for it before creating the index.

You can then configure logstash to apply this template when sending data.

---

<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: [July 18, 2022, 2:25pm UTC](https://discuss.elastic.co/t/create-nested-object-mapping-using-logstash-unloading-from-postgres/307661/5 "2022-07-18T14:25:24Z")

</div>

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