# Pulling data from two different DB with Logstash JDBC Input and merging input events data

**URL:** <https://discuss.elastic.co/t/pulling-data-from-two-different-db-with-logstash-jdbc-input-and-merging-input-events-data/283973>\
**Category:** Logstash\
**Created:** [September 12, 2021, 12:47pm UTC](https://discuss.elastic.co/t/pulling-data-from-two-different-db-with-logstash-jdbc-input-and-merging-input-events-data/283973 "2021-09-12T12:47:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![e-fo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/e-fo/32/87474_2.png) [@e-fo](https://discuss.elastic.co/u/e-fo)\
**Post date:** [September 12, 2021, 12:47pm UTC](https://discuss.elastic.co/t/pulling-data-from-two-different-db-with-logstash-jdbc-input-and-merging-input-events-data/283973/1 "2021-09-12T12:47:33Z")

</div>

Hi and thanks for your great community.

I have two database that I want configuring a pipeline with Logstash that pulling data from these two database and merging the input events based on one same field in these events and pushing one merged event into Elasticsearch.

I think i must using the JDBC input plugin twice in Logstash input block like this config:

```auto
input {
  jdbc {
    jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "connection str for first db"
    jdbc_user => "root"
    jdbc_password => "password"
    schedule => "* * * * *"
    statement => "select * from table1"
    type => "table1"
  }
  jdbc {
    jdbc_driver_library => "/Users/logstash/mysql-connector-java-5.1.39-bin.jar"
    jdbc_driver_class => "com.mysql.jdbc.Driver"
    jdbc_connection_string => "connection str for second db"
    jdbc_user => "root"
    jdbc_password => "password"
    schedule => "* * * * *"
    statement => "select * from table2"
    type => "table2"
  }
  # add more jdbc inputs to suit your needs 
}

filter {
	.
	.
	.
}

output {
    elasticsearch {
        index => "testdb"
        document_type => "idx"
        hosts => "elstic host"
    }
}

```

but I haven't any idea about how can I merged the input events based on one same field like bellow:

```auto
#event 1
{
	"user_id": 90876,
	"user_register_ts": 1631449749
}
#event 2
{
	"user_id": 89090,
	"user_register_ts": 1631444700
}
#event 3
{
	"user_id": 90876,
	"store": "GooglePlay",
	"coin_num": "780"
}
#event 4
{
	"user_id": 89090,
	"store": "AppStore",
	"coin_num": "1037"
}

## after merging process

# merged event 1 (merged event 1 and 3 based on user_id)
{
	"user_id": 90876,
	"user_register_ts": 1631449749,
	"store": "GooglePlay",
	"coin_num": "780"
}

# merged event 2 (merged event 2 and 4 based on user_id)
{
	"user_id": 89090,
	"user_register_ts": 1631444700,
	"store": "AppStore",
	"coin_num": "1037"
}

```

Can you help me about methods that helps me to merging these events in logstash?

**Thanks for any response.**

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [September 12, 2021, 3:46pm UTC](https://discuss.elastic.co/t/pulling-data-from-two-different-db-with-logstash-jdbc-input-and-merging-input-events-data/283973/2 "2021-09-12T15:46:14Z")

</div>

Instead of using two jdbc inputs you might want to use one jdbc input and a jdbc\_static filter to enrich it.

---

<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 10, 2021, 3:46pm UTC](https://discuss.elastic.co/t/pulling-data-from-two-different-db-with-logstash-jdbc-input-and-merging-input-events-data/283973/3 "2021-10-10T15:46:22Z")

</div>

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