# Logstash multiple jdbc input and clone

**URL:** <https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739>\
**Category:** Logstash\
**Created:** [June 19, 2020, 6:46am UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739 "2020-06-19T06:46:51Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [June 19, 2020, 6:46am UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739/1 "2020-06-19T06:46:51Z")

</div>

I want to synchronize 2 postgres tables with 3 elasticsearch indexes.

I'm going to split one of the tables and synchronize it with two indexes.

so I'm cloning one of those tables. Divide the cloned things into 2 indexes and make outputs.

In other words, there are three outputs. I wonder if it is possible to do this in one conf file. I want you to let me know if anyone knows about this. Share your experience.

here is my code below.

```auto
input {
     jdbc {
        jdbc_connection_string => "jdbc:postgresql://localhost:5432/atlasdb?useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf8"
        jdbc_user => "atlas"
        jdbc_password => "atlas"
        jdbc_validate_connection => true
        jdbc_driver_library => "/lib/postgres-42-test.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        schedule => "* * * * *"
        statement => "select *, (select json_build_object('region_id', region_id, 'region_name', region_name, 'region_name_kr', region_name_kr, 'region_type', region_type, 'region_code', region_code)::jsonb from expedia_region_union where region_id = c.region_id ) as region_json from expedia_airport_more c"
        type => "A"
   }

   jdbc {
        jdbc_connection_string => "jdbc:postgresql://localhost:5432/atlasdb?useTimezone=true&useLegacyDatetimeCode=false&serverTimezone=UTC&useSSL=false&useUnicode=true&characterEncoding=utf8"
        jdbc_user => "atlas"
        jdbc_password => "atlas"
        jdbc_validate_connection => true
        jdbc_driver_library => "/lib/postgres-42-test.jar"
        jdbc_driver_class => "org.postgresql.Driver"
        schedule => "* * * * *"
        statement => "SELECT region_id, region_name, region_name_full, region_name_kr, continent::text, country::text from expedia_region_union order by region_id asc limit 100"
        type => "B"
   }

   stdin {
        codec => plain { charset => "UTF-8"}
   }

}
filter {
    ruby {
            code => "
                    require 'json'
                    continent_json = JSON.parse(event.get('continent').to_s)
                    event.set('continent', continent_json)
                    country_json = JSON.parse(event.get('country').to_s)
                    event.set('country', country_json)
                    "
            }
    date {
        match => ['time', 'UNIX']
    }

    if [type] == 'B' {
        clone {
            clones => ['B-1', 'B-2']
        }

        if [type] == 'B-1' {
            mutate {
                add_field => {"[@metadata][type]" => "B-1-test"}
            }
        } else {
            mutate {
                add_field => {"[@metadata][type]" => "B-2-test"}
            }
        }

    } else {
        mutate {
            add_field => {"[@metadata][type]" => "A-test"}
        }
    }
}

output {
    stdout { codec => rubydebug }

    if [@metadata][type] == 'A-test' {
        elasticsearch {
            hosts => ["localhost:9200"]
            index => "2020-06-19-fri"
            doc_as_upsert => true
            action => "update"
            document_id => "%{region_id}"
        }
    }
    else if [@metadata][type] == 'B-1-test' {
        elasticsearch {
            hosts => ["localhost:9200"]
            index => "B-1-test"
            doc_as_upsert => true
            action => "update"
            document_id => "%{region_id}"
        }
    } else {
        elasticsearch {
            hosts => ["localhost:9200"]
            index => "B-2-test"
            doc_as_upsert => true
            action => "update"
            document_id => "%{region_id}"
        }
    }
}

```

---

<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:** [June 19, 2020, 11:59am UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739/2 "2020-06-19T11:59:01Z")

</div>

What is your question?

---

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [June 22, 2020, 2:35am UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739/3 "2020-06-22T02:35:32Z")

</div>

The question is here, as you can see in the text.

"I wonder if it is possible to do this in one conf file. I want you to let me know if anyone knows about this. Share your experience."

I was wondering if I had to create a 'conf' file by setting, or manage it as a single file.

Right now I'm managing it as one file, so there's no problem.

Anyway, thanks for the answer.

---

<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:** [June 22, 2020, 1:50pm UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739/4 "2020-06-22T13:50:25Z")

</div>

It is certainly possibly to have multiple outputs in a single configuration file, but since you are already doing that you obviously know that. Again, it is unclear what you are asking.

---

<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 20, 2020, 1:50pm UTC](https://discuss.elastic.co/t/logstash-multiple-jdbc-input-and-clone/237739/5 "2020-07-20T13:50:26Z")

</div>

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