how can a table of all databases be sent to elasticsearch?

Viewed 115

Here's my situation.

  1. Food_database is in mysql.
  2. There are 130 tables in food_database
  3. I would like to send 130 tables to elasticsearch via logstash_jdbc.

-> how can a table of all databases be sent to elasticsearch?

my conf file (attempt)

input {
    jdbc {
        clean_run => true
        jdbc_driver_library => "C:\ElasticSearch\mysql-connector-java-8.0.23\mysql-connector-java-8.0.23.jar"
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        jdbc_connection_string => "jdbc:mysql://localhost:3306/food_database?useSSL=false&user=root&password=1234"
        jdbc_user => "root"
        jdbc_password => "1234"
        schedule => "* * * * *"
        statement => "select * from ??????"
        #use_column_value => true
        #tracking_column => "jobid"
    }
}
output{
    elasticsearch {
        hosts => "localhost:9200"
        index => "test_indexfile"
    }
    stdout {
        codec => rubydebug
    }
}

But I don't know how to send all 130 tables in food_databases.

I found a similar question through googling, but I couldn't solve it.

-> save whole database to elasticsearch using logstash

-> https://dzone.com/articles/migrating-mysql-data-to-elasticsearch-using-logsta

Please help me.

update posting (tables in food_database)

+--------------------------------------+
| Tables_in_food_database              |
+--------------------------------------+
| access_token                         |
| activity                             |
| address                              |
| answer_abuse_reason                  |
| answer_report_abuse                  |
| attribute                            |
| attribute_group                      |
| banner                               |
| banner_group                         |
| banner_image                         |
| banner_image_description             |
| blog                                 |
| blog_related                         |
| category                             |
| category_commission                  |
| category_description                 |
| category_path                        |
| contact                              |
| country                              |
| coupon                               |
| coupon_product_category              |
| coupon_usage                         |
| coupon_usage_product                 |
| currency                             |
| customer                             |
| customer_activity                    |
| customer_cart                        |
| customer_document                    |
| customer_group                       |
| customer_ip                          |
| customer_transaction                 |
| customer_wishlist                    |
| delivery_allocation                  |
| delivery_location                    |
| delivery_location_to_location        |
| delivery_person                      |
| delivery_person_to_location          |
| delivery_status                      |
| email_template                       |
| geo_zone                             |
| jobs                                 |
| language                             |
| login_log                            |
| manufacturer                         |
| migrations                           |
| order                                |
| order_cancel_reason                  |
| order_history                        |
| order_log                            |
| order_product                        |
| order_product_log                    |
| order_status                         |
| order_total                          |
| page                                 |
| page_group                           |
| payment                              |
| payment_archive                      |
| payment_items                        |
| payment_items_archive                |
| paypal_order                         |
| paypal_order_transaction             |
| permission_module                    |
| permission_module_group              |
| plugins                              |
| price_update_file_log                |
| product                              |
| product_answer                       |
| product_answer_like_dislike          |
| product_attribute                    |
| product_description                  |
| product_discount                     |
| product_image                        |
| product_price_log                    |
| product_question                     |
| product_rating                       |
| product_related                      |
| product_special                      |
| product_stock_alert                  |
| product_tag                          |
| product_tire_price                   |
| product_to_category                  |
| product_varient                      |
| product_varient_option               |
| product_varient_option_details       |
| product_varient_option_image         |
| product_view_log                     |
| quotation                            |
| razorpay_order                       |
| razorpay_order_transaction           |
| service                              |
| service_category                     |
| service_category_path                |
| service_enquiry                      |
| service_image                        |
| service_to_category                  |
| sessions                             |
| settings                             |
| settlement                           |
| settlement_item                      |
| site_filter                          |
| site_filter_category                 |
| site_filter_section                  |
| site_filter_section_item             |
| sku                                  |
| stock_log                            |
| stock_status                         |
| stripe_order                         |
| stripe_order_transaction             |
| tax                                  |
| trend                                |
| trend_image                          |
| trend_recommend                      |
| user_group                           |
| users                                |
| varients                             |
| varients_value                       |
| vendor                               |
| vendor_category                      |
| vendor_coupon                        |
| vendor_coupon_product_category       |
| vendor_global_setting                |
| vendor_invoice                       |
| vendor_invoice_item                  |
| vendor_order_archive                 |
| vendor_order_archive_log             |
| vendor_order_products                |
| vendor_order_status                  |
| vendor_orders                        |
| vendor_orders_log                    |
| vendor_payment                       |
| vendor_payment_archive               |
| vendor_product                       |
| widget                               |
| widget_item                          |
| zone                                 |
| zone_to_geo_zone                     |
+--------------------------------------+
136 rows in set (0.00 sec)

I would like to send all the values of my goals 136 tables to elasticsearch via logstash.

1 Answers

If running a script next to logstash would be an option I would go for the following approach:

  • Create a bash script (or whatever language your preference has), put this in cron to do a simple 'show tables' and use the output in order to create 130 config files only containing the INPUT part for logstash with a naming convention like 'INPUT_tablename.conf'. This script should create the config as shown above, for each table that exists.
    • Make sure it lists the INPUT_* files in the directory and deletes the ones that no longer exists.
    • Make sure that when a file already exists it does not touch it
  • have your FILTER.conf and OUTPUT.conf in the same directory
  • Put you logstash in auto reload config mode

By doing it this way you seperate the thing you are struggling with and allows the database to have changes in tables, new ones that are added, and old ones that might be deleted or renamed.

I've learned to do it this way on clusters that I know will become very large and where I need to learn when the maximum io is being hit so i know when to add new nodes to which layer without killing the complete setup.

Related