# MYSQL to ELASTICSEARCH multiple tables at once

**URL:** <https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040>\
**Category:** Logstash\
**Created:** [August 6, 2019, 3:09pm UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040 "2019-08-06T15:09:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karnish\_Master](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnish_master/32/51489_2.png) [@Karnish\_Master](https://discuss.elastic.co/u/Karnish_Master)\
**Post date:** [August 6, 2019, 3:09pm UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040/1 "2019-08-06T15:09:36Z")

</div>

I am porting data from mysql to elastisearch , I am using type =\> "table\_type" in input and output to bifurcate into different tables ,data is going proper for each index however i am getting extra field named type with value which i have defined in type i.e. (table\_1\_type) for every record.

Below is sample config

INPUT

```
   				jdbc {
                                       jdbc_driver_library => "/usr/share/java/mysql-connector-java-8.0.12.jar"
                                        # jdbc_driver_library => "/usr/share/java/mysql-connector-java.jar"
                                        jdbc_driver_class => "com.mysql.jdbc.Driver"
                                        jdbc_connection_string => "jdbc:mysql://MYSQL:3306/database"
                                        jdbc_user => "username"
                                        jdbc_password => "password"
                                        jdbc_paging_enabled => true
                                        jdbc_page_size => 200000
                                        type => "table_1_type"
                                        statement => "select columns from table_1"
                                        last_run_metadata_path => "/etc/logstash/conf.d/lastrun/.logstash_jdbc_test_last_run"
                                }

```

OUTPUT

```
		 if [type] == "table_1_type" {

				elasticsearch {
					index => "table_1"
					document_type => "_doc"
					hosts => "localhost:9200"
					document_id => "%{unqiue_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:** [August 6, 2019, 3:14pm UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040/2 "2019-08-06T15:14:24Z")

</div>

Use mutate+rename to move it to [@metadata][type], then you can still use it in a conditional but it will not get added to the document in elasticsearch.

---

<div class="post-metadata">

**Author:** ![Karnish\_Master](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karnish_master/32/51489_2.png) [@Karnish\_Master](https://discuss.elastic.co/u/Karnish_Master)\
**Post date:** [August 7, 2019, 5:53am UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040/3 "2019-08-07T05:53:48Z")

</div>

@Badger :- Thanks for reply !It will be helpful if you can explain with example.

---

<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:** [August 7, 2019, 10:59am UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040/4 "2019-08-07T10:59:02Z")

</div>

Use mutate like this

```
mutate { rename => { "type" => "[@metadata][type]" } }

```

Then anywhere where you test [type] change it to

```
if [@metadata][type] == "table_1_type" {
```

---

<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:** [September 4, 2019, 10:59am UTC](https://discuss.elastic.co/t/mysql-to-elasticsearch-multiple-tables-at-once/194040/5 "2019-09-04T10:59:09Z")

</div>

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