# Logstash JDBC index field with multiple values

**URL:** <https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498>\
**Category:** Logstash\
**Created:** [September 14, 2019, 9:22am UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498 "2019-09-14T09:22:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kevin\_Juliano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_juliano/32/48845_2.png) [@Kevin\_Juliano](https://discuss.elastic.co/u/Kevin_Juliano)\
**Post date:** [September 14, 2019, 9:22am UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/1 "2019-09-14T09:22:08Z")

</div>

Newbie here, I am using Logstash to index data on our PostgreSQL database, the thing is, we have a very complex query for just one record,e.g 1 table has many relations.

Is it possible to format the index like this:

```auto
{
    "id": 1,
    "customer_type": "design",
    "number": "00010231",
    "country": "US",
    "date": "2019-02-12",
    "address": "Street City State",
    "orders": { // table
        "order_id": 1,
        "order_desc": null,
        ...
    },
    "products_ordered": [ // other table
        {
            "id": 1,
            "sequence": 0,
            "product_name": "sample product",
            ...,
            ...,
        }
    ],

.... // other info

```

I am indexing the data by writing super complicated and very long query but I don't think that's the right way to do.

is there any way or technique on how to do it?

Any help will be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [September 14, 2019, 10:21pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/2 "2019-09-14T22:21:53Z")

</div>

if I understood right, you are using `logstash-input-jdbc` to read data from PostgreSQL and send to ElasticSearch (that's what you mean with 'index data', right ?)

you could have this single SQL query that captures it all, and do the transformation using some `logstash-filter-*`

I'd recommend making 1 `logstash-input-jdbc` and some `logstash-filter-jdbc_streaming` to enrich your data using some fields' values from the original message to make the linking, and other filters for normalisation, renaming, aggregation ...

see :

- [https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html](https://www.elastic.co/guide/en/logstash/current/plugins-inputs-jdbc.html)
- [https://www.elastic.co/guide/en/logstash/current/plugins-filters-jdbc\_streaming.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-jdbc_streaming.html)

---

<div class="post-metadata">

**Author:** ![Kevin\_Juliano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_juliano/32/48845_2.png) [@Kevin\_Juliano](https://discuss.elastic.co/u/Kevin_Juliano)\
**Post date:** [September 15, 2019, 1:55pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/3 "2019-09-15T13:55:56Z")

</div>

Hi @endersonmaia, Thank you for your response, I read about the links that you gave me and did some reasearch, I think this is the right answer to what I want to do, but I don't know where to start, Sorry, I'm still confused because I don't understand how am I going to add the information from one table to another. I'm not sure but I think the `parameter` option is the key, I am hoping you can provide me at least the very basic setup/configuration for it.

I really appreciate you helping me on this. 🙂

---

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [September 15, 2019, 10:44pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/4 "2019-09-15T22:44:24Z")

</div>

considering you have two tables `Sales` and `SalesItems`, and you want a JSON message with the sales details and itens details

```auto
input {
  jdbc {
    ...
    tracking_column => "id"
    statement => "SELECT * FORM Sales WHERE id > :sql_last_value"
    ...
  }
}
...
jdbc_streaming {
  ...
  statement => "SELECT * FROM SalesItems WHERE sales_id = :sales_id"
  parameters => {
    "sales_id" => "[id]"
  }
  target => "[itens]"
  ...
}

```

It would generate a message like

```
{
  "id": 1
  "total_ammount": 10.50
  "items" : [
    { "id" : 1, "product_name": "computer", "value": 10.0 },
    { "id" : 2, "product_name": "mouse", "value": 0.50 }
  ]
}
```

---

<div class="post-metadata">

**Author:** ![Kevin\_Juliano](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kevin_juliano/32/48845_2.png) [@Kevin\_Juliano](https://discuss.elastic.co/u/Kevin_Juliano)\
**Post date:** [September 17, 2019, 2:13pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/6 "2019-09-17T14:13:14Z")

</div>

Hi @endersonmaia, I've got a lot of errors at first but I got it all working, esp. on date thing.

THANK YOU VERY MUCH!

---

<div class="post-metadata">

**Author:** ![endersonmaia](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/endersonmaia/32/17308_2.png) [@endersonmaia](https://discuss.elastic.co/u/endersonmaia)\
**Post date:** [September 17, 2019, 8:40pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/7 "2019-09-17T20:40:20Z")

</div>

@Kevin_Juliano, I suggest you to share your solution, maybe others with a similar problem could use this information.

---

<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:** [October 15, 2019, 8:48pm UTC](https://discuss.elastic.co/t/logstash-jdbc-index-field-with-multiple-values/199498/8 "2019-10-15T20:48:37Z")

</div>

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