Use Case: You got a postgres database and you need to move data to elastic search for exploration
Setup Elastic Search on Ubuntu
sudo apt updatesudo apt install default-jdkwget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -- Add the Elasticsearch repository to the package manager
echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-7.x.list - Update the package manager
sudo apt update - Install Elasticsearch:
sudo apt install elasticsearch - Configure Elasticsearch:
sudo vi /etc/elasticsearch/elasticsearch.yml- Inside the file, find the
network.hostsetting set it to the IP address of your server or use0.0.0.0to listen on all network interfaces. - if using network host as 0.0.0.0 set, discovery.seed_hosts: [“127.0.0.1”, “[::1]”]
- set security –
- xpack.security.enabled: true
- xpack.security.transport.ssl.enabled: true
- Start and enable Elasticsearch:
sudo systemctl start elasticsearchsudo systemctl enable elasticsearch
- Verify Elasticsearch installation:
-XGET http://localhost:9200 - sudo /usr/share/elasticsearch/bin/elasticsearch-setup-passwords interactive
Setup LogStash
- Install Logstash: https://www.elastic.co/downloads/logstash
- Create a Logstash Configuration File:
postgresql.conf - Run Logstash:
bin/logstash -f /path/to/postgresql.conf
Sample postgresql.conf
input {
jdbc {
jdbc_connection_string => "jdbc:postgresql://localhost:5432/postgres"
jdbc_user => "username"
jdbc_password => "password"
jdbc_driver_library => "/path/postgresql.jar"
jdbc_driver_class => "org.postgresql.Driver"
statement => "select id, name, date_of_birth from employee;"
jdbc_default_timezone => "UTC"
jdbc_fetch_size => 1000
}
}
output {
elasticsearch {
hosts => ["http://localhost:9200"]
index => "employee_index"
document_id => "%{employee_id}"
user => "elastic"
password => "password"
}
}
