# How to configure logstash file to make nested object inside another nested filed from sql query?

**URL:** https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077
**Category:** Logstash
**Created:** [March 23, 2021, 10:46am UTC](https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077 "2021-03-23T10:46:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![My-project-repositor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/my-project-repositor/32/85949_2.png) [@My-project-repositor](https://discuss.elastic.co/u/My-project-repositor)
#### Post date: [March 23, 2021, 10:46am UTC](https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077/1 "2021-03-23T10:46:57Z")

</div>

I am new in Elasticsearch and logstash and I have an issue with nested objects. So what I want to ask is how can I create index with multiple nested fields inside another nested fields.

How can I build the data inside logstash file configuration from data from postgres to index something like below inside elasticsearch?

For example, I have a Product which have raw materials and raw materials have substances

```auto
product {
 id: 1,
 name: "name",
 raw_materials: [{
  id: 1,
  name: "raw_name",
  substances: [{
    id: 1,
    name: "sub_name",
  }]
 }]
}

```

Help me please

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 6, 2021, 9:42am UTC](https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077/2 "2021-04-06T09:42:03Z")

</div>

I don't think there's an easy way for doing such a thing.

But I'd read [Jdbc input plugin | Logstash Reference [7.12] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html#_configuring_multiple_sql_statements)

That's being said, I shared most of my thoughts there: [http://david.pilato.fr/blog/2015/05/09/advanced-search-for-your-legacy-application/](http://david.pilato.fr/blog/2015/05/09/advanced-search-for-your-legacy-application/)

Basically, I'd recommend modifying the application layer if possible and send data to elasticsearch in the same "transaction" as you are sending your data to the database instead of trying to read that later and try to compose complex objects (this has a significant cost on the source database).

Have also a look at this ["live coding" recording](https://www.elastic.co/fr/blog/how-to-add-powerful-search-existing-sql-applications-elasticsearch-video-tutorial).

---

<div class="post-metadata">

### Author: ![My-project-repositor](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/my-project-repositor/32/85949_2.png) [@My-project-repositor](https://discuss.elastic.co/u/My-project-repositor)
#### Post date: [April 6, 2021, 10:28am UTC](https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077/3 "2021-04-06T10:28:12Z")

</div>

Thanks for your answer

We already have a lot of data in the current database so sending data in ES with the same transaction in the database may not be possible.

Do you think that flatten the data without nesting all the fields would be approprite to perform search?

---

<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: [May 4, 2021, 10:28am UTC](https://discuss.elastic.co/t/how-to-configure-logstash-file-to-make-nested-object-inside-another-nested-filed-from-sql-query/268077/4 "2021-05-04T10:28:33Z")

</div>

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